XML NullPointerException
in
Programming Questions
•
2 months ago
Hi,
This used to work but now gives a NullPointerException. I can't figure out what's up, but I'm guessing the newer version of Processing (2.0.x) had a syntax change or something??? It's driving me crazy, please help! :-)
Here is the XML file I'm loading:
- <?xml version="1.0"?>
- <harmonograph version="2.0">
- <instance id="0" _d="1414.473" _c="1268.7473" _p="3511.7415" _q="4427.864" _r="2635.5127" _A="0.5578053" _B="0.06687627" _u="0.40685725" _u1="0.05810337" _v="0.00901467" _v1="0.6092852" _R="3.5049737E-4" _S="3.57546E-4" _f="0.052110754" _f1="0.024216956" _g="2.8014755" _g1="1.1454126" _h="0.0023904506" _s="10000.0" _dt="0.01" _sw="0.0020" _c1="236.39992" _c2="245.5904" _c3="199.0" _c4="186.17993" _paper_scale="0.056286596"></instance>
- <instance id="1" _d="75.58671" _c="923.0078" _p="2236.305" _q="2558.7473" _r="1439.7762" _A="0.049523104" _B="0.07326763" _u="1.0305866" _u1="0.104935005" _v="0.056840375" _v1="0.61773765" _R="9.204476E-4" _S="7.340446E-4" _f="0.47582477" _f1="6.497495E-4" _g="1.5455143" _g1="0.5479465" _h="0.0019688155" _s="10000.0" _dt="0.01" _sw="0.0020" _c1="233.58257" _c2="114.20393" _c3="161.74295" _c4="228.1528" _paper_scale="0.07382174"></instance>
- <instance id="2" _d="4541.5713" _c="3129.408" _p="2517.585" _q="967.66296" _r="715.6475" _A="0.71969116" _B="0.058555778" _u="0.21462521" _u1="0.11627076" _v="0.10193885" _v1="0.6912108" _R="1.9483913E-4" _S="2.0797868E-4" _f="0.43537554" _f1="0.04506056" _g="1.2340766" _g1="2.9522796" _h="0.001092679" _s="10000.0" _dt="0.01" _sw="0.0020" _c1="123.6345" _c2="93.433395" _c3="168.05882" _c4="58.669914" _paper_scale="0.11436498"></instance>
- </harmonograph>
Here is the XML function I'm using to process the file:
- public int loadXML() {
- int xmlObjects = -1;
- String xmlFile;
- XML xml; // Declare XMLElement object
- String path = sketchPath + "/data";
- String[] filenames = listFileNames(path);
- for (int i = 0; i < filenames.length; i++) {
- if (filenames[i].toLowerCase().endsWith(".xml")) {
- xmlFile = filenames[i];
- xml = loadXML(filenames[i]);
- if (xml.getFloat("version") == _version) {
- xmlObjects = xml.getChildCount();
- pArr = new Harmonograph[xmlObjects];
- for (int h = 0; h < xmlObjects; h++) {
- XML kid = xml.getChild(h);
- pArr[h] = new Harmonograph(h, 1);
- pArr[h]._d = kid.getFloat("_d");
- pArr[h]._c = kid.getFloat("_c");
- pArr[h]._p = kid.getFloat("_p");
- pArr[h]._q = kid.getFloat("_q");
- pArr[h]._r = kid.getFloat("_r");
- pArr[h]._A = kid.getFloat("_A");
- pArr[h]._B = kid.getFloat("_B");
- pArr[h]._u = kid.getFloat("_u");
- pArr[h]._u1 = kid.getFloat("_u1");
- pArr[h]._v = kid.getFloat("_v");
- pArr[h]._v1 = kid.getFloat("_v1");
- pArr[h]._R = kid.getFloat("_R");
- pArr[h]._S = kid.getFloat("_S");
- pArr[h]._f = kid.getFloat("_f");
- pArr[h]._f1 = kid.getFloat("_f1");
- pArr[h]._g = kid.getFloat("_g");
- pArr[h]._g1 = kid.getFloat("_g1");
- pArr[h]._h = kid.getFloat("_h");
- pArr[h]._s = kid.getFloat("_s");
- pArr[h]._dt = kid.getFloat("_dt");
- pArr[h]._sw = kid.getFloat("_sw");
- pArr[h]._c1 = kid.getFloat("_c1");
- pArr[h]._c2 = kid.getFloat("_c2");
- pArr[h]._c3 = kid.getFloat("_c3");
- pArr[h]._c4 = kid.getFloat("_c4");
- pArr[h]._paper_scale = kid.getFloat("_paper_scale");
- // print out variable values
- println("Variables generated from XML file '" + xmlFile + "'");
- println("Harmonograph Object: " + pArr[h]._id);
- println("Stroke color: " + pArr[h]._c1 + "," + pArr[h]._c2 + "," + pArr[h]._c3 + "," + pArr[h]._c4);
- println("First x, y: " + pArr[h]._x + "," + pArr[h]._y);
- println("Paper scale: " + pArr[h]._paper_scale);
- println("d = " + pArr[h]._d);
- println("c = " + pArr[h]._c);
- println("p = " + pArr[h]._p);
- println("q = " + pArr[h]._q);
- println("r = " + pArr[h]._r);
- println("A = " + pArr[h]._A);
- println("B = " + pArr[h]._B);
- println("u = " + pArr[h]._u);
- println("u1 = " + pArr[h]._u1);
- println("v = " + pArr[h]._v);
- println("v1 = " + pArr[h]._v1);
- println("R = " + pArr[h]._R);
- println("S = " + pArr[h]._S);
- println("f = " + pArr[h]._f);
- println("f1 = " + pArr[h]._f1);
- println("g = " + pArr[h]._g);
- println("g1 = " + pArr[h]._g1);
- println("h = " + pArr[h]._h);
- println("");
- }
- println("Harmonograph Version " + _version);
- println("http://www.davidcool.com/");
- println("");
- } else {
- println("****************************************************************************************************");
- println("ERROR LOADING XML FILE DATA!!!");
- println("Version mismatch!");
- println("XML harmonograph version: " + xml.getFloat("version") + " Sketch harmonograph version: " + _version);
- println("Be sure that the XML file was generated by this version of the sketch.");
- println("Defaulting to random variable generation...");
- println("****************************************************************************************************");
- println("");
- }
- }
- }
- return xmlObjects;
- }
Line 18 in the snippet above is highlighted in yellow and seems to be throwing the error. I've combed over this several times and can't seem to figure out what's causing this!
Thanks,
David
1