Class PApplet is not reading a file
in
Programming Questions
•
3 years ago
Hi, I'm having a problem here reading a file from a Class.
I'm working on a .glif files reader (typographic info), basically an XML reader, and I don't have any problem accessing the files (with the XMLElement constructor) from the main program but when I try to access the file from a class I get a NullPointerException. The comments are in catalan, sorry.
Here's the code:
///////////// Main program
XMLElement xml;
Lletra exemple;
void setup() {
smooth();
noStroke();
size(1200, 1200);
exemple = new Lletra("A_");
exemple.setup();
println(exemple.nodes.length);
translate(width, height/1.5);
rotate(PI);
beginShape();
for(int i = 0; i < exemple.nodes.length; i++){
if (exemple.nodes[i].tipus == null){
println("Res de res");
}else if (exemple.nodes[i].tipus.equals("curve")){
bezierVertex(exemple.nodes[i-2].x, exemple.nodes[i-2].y, exemple.nodes[i-1].x, exemple.nodes[i-1].y, exemple.nodes[i].x, exemple.nodes[i].y);
}else{
vertex(exemple.nodes[i].x, exemple.nodes[i].y);
println(exemple.nodes[i].x + " / " + exemple.nodes[i].y);
}
}
endShape(CLOSE);
}
///////////// Class Lletra
class Lletra extends PApplet {
//Variables
String nomLletra;
XMLElement xml, nom;
XMLElement[] punts;
int numNodes;
Punt[] nodes;
//Constructor
public Lletra (String nomLletra){
this.nomLletra = nomLletra;
}
void setup(){
//Obre l'arxiu XML
xml = new XMLElement(this, "Kids/glyphs/" + nomLletra + ".glif");
//Carreguem els punts en un array de XMLElements
punts = xml.getChildren("outline/contour/point");
//Iniciem l'array que contindra els punts de la lletra
nodes = new Punt[punts.length];
for (int i = 0; i < punts.length; i++){
nodes[i] = new Punt(punts[i].getIntAttribute("x"), punts[i].getIntAttribute("y"), punts[i].getStringAttribute("type"));
}
}
public void loadLletra(){
}
}
Here's the error code I get:
Kids/glyphs/A_.glif does not exist or could not be read
processing.app.debug.RunnerException: NullPointerException
at processing.app.Sketch.placeException(Sketch.java:1543)
at processing.app.debug.Runner.findException(Runner.java:583)
at processing.app.debug.Runner.reportException(Runner.java:558)
at processing.app.debug.Runner.exception(Runner.java:498)
at processing.app.debug.EventThread.exceptionEvent(EventThread.java:367)
at processing.app.debug.EventThread.handleEvent(EventThread.java:255)
at processing.app.debug.EventThread.run(EventThread.java:89)
Exception in thread "Animation Thread" java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:61)
at java.io.BufferedReader.<init>(BufferedReader.java:76)
at java.io.BufferedReader.<init>(BufferedReader.java:91)
at java.io.LineNumberReader.<init>(LineNumberReader.java:52)
at processing.xml.StdXMLReader.<init>(StdXMLReader.java:178)
at processing.xml.XMLElement.parseFromReader(XMLElement.java:247)
at processing.xml.XMLElement.<init>(XMLElement.java:222)
at UFOfal$Lletra.setup(UFOfal.java:71)
at UFOfal.setup(UFOfal.java:29)
at processing.core.PApplet.handleDraw(PApplet.java:1583)
at processing.core.PApplet.run(PApplet.java:1503)
at java.lang.Thread.run(Thread.java:613)
Any Guess??
1