Working on a fairly simple probgram... the portions that I think are relevant are below.
bauercalc.pde
Code:
int nProb = 0;
Problem[] allProblems;
int i=0;
int j=0;
int k=0;
int l=0;
void setup(){
//load problems file
String rawProbList[] = loadStrings("problems.txt");
String thisLine;
for(i=0;i < rawProbList.length; i++){
//above reads each line. logic follows..
thisLine = rawProbList[i];
//is it a comment?
if((thisLine.length() < 2) || (thisLine.substring(0,2).equals("//") == false)){
//it's not a comment
//Is it a header?
if(thisLine.equals("HEADER") == true){
j=0;
//First "line" of the problem
//Also update the count of valid lines...
nProb++;
}else{
//it's a content line, not header
switch(j){
case 0:
//need to make a new problem; this line gives the filename
allProblems = (Problem[])append(allProblems, new Problem(thisLine));
break;
case 1:
//update topic of this problem...
allProblems[nProb-1].topic = int(thisLine);
break;
case 2:
//update DC this problem...
allProblems[nProb-1].level = int(thisLine);
break;
case 3:
//update answer of this problem...
allProblems[nProb-1].answer = thisLine.charAt(0);
break;
}
//increment which one we're on
j++;
}
}//end of dealing with a valid line
}//end of reading problems.txt
problemObj.pde
Code:class Problem
{
//class representing the current problem
char answer;
int topic;
int level;
String fileName;
PImage visual;
void display(int ecks, int why){
//draw it
image(visual, ecks, why);
}
Problem(String ifileName){
fileName = ifileName;
//load it
visual = loadImage(fileName);
}
}
I'm getting a NullPointerException, with output as follows:
Code:Exception in thread "Animation Thread" java.lang.NullPointerException
at java.lang.reflect.Array.getLength(Native Method)
at processing.core.PApplet.append(PApplet.java:4691)
at bauercalc.setup(bauercalc.java:92)
at processing.core.PApplet.handleDraw(PApplet.java:1383)
at processing.core.PApplet.run(PApplet.java:1311)
at java.lang.Thread.run(Unknown Source)
I've had to deal with several NullPointerExceptions from syntax issues, but they all highlighted a specific line. This has no line reference... and the error still occurs when I replace thisLine.length() and rawProbList.length with constants.
Any thoughts? I'm afraid I'm new at both Processing and Java... any advice or aid would be appreciated!