Exception in event handler error - is it scope?
in
Programming Questions
•
1 year ago
I declare two global integer arrays BoxX[] and BoxY[] at the beginning of my program.
- int BoxX[];
- int BoxY[];
I have a procedure
void loadTemplateData(int Tnum) -
code below - to read a text file and stuff the arrays with integers from the text file. I can read and parse the numbers and display them back no problem, but as soon as I try to put the values into array slots I get the following error:
############# EXCEPTION IN EVENT HANDLER #############
An error occured during execution of the eventhandler:
CLASS: JupiterShowDemo_v6_G4P_b METHOD: handleButtonEvents
Caused by java.lang.NullPointerException
JupiterShowDemo_v6_G4P_b.loadTemplateData(JupiterShowDemo_v6_G4P_b.java:608)
########################################################
When I comment out the lines that fill the array the procedure runs fine and displays the results in println statements. As soon as I un-comment the array fillers it runs the last println statement before filling the array and then throws the error.
I know the error refers to the G4P library but I think this is a programming issue as the G4P button simply calls the procedure and should have no involvement in the procedure - that is why I posted it here.
Here's the code:
- void loadTemplateData(int Tnum){
- String lines[] = loadStrings("Templates/Template"+ Tnum + ".txt");
- templateTitle = lines[0];
- String sizes[] = split(lines[1], ',');
- txtWidth = int(sizes[0]);
- txtHeight = int(sizes[1]);
- println("Template "+templateTitle+" uses boxes "+txtWidth+" by "+txtHeight+" in the following locations:");
- for (int i = 2; i < (lines.length-1); i++) {
- String pieces[] = split(lines[i], ',');
- println("Line " + (i+1) + " of " + lines.length);
- println("Boxes at :" + pieces[0] +" , "+ pieces[1]);
- BoxX[i-2] = parseInt(pieces[0]); //commenting out this and the next 2 lines avoids the error
- BoxY[i-2] = parseInt(pieces[1]);
- println("rectangle location = " + BoxX[i-2] + " , " + BoxY[i-2]);
- }
- }
Nametags, 8-up
100,100
124,123
124,367
271,367
544,205
544,340
544,475
686,340
686,475
Here's the console output from lines 10, 13 & 14 when the array-filling lines (15,16,17) are commented out, showing that the textfile reading is sound:
Template Nametags, 8-up uses boxes 100 by 100 in the following locations:
Line 3 of 11
Boxes at :124 , 123
Line 4 of 11
Boxes at :124 , 367
Line 5 of 11
Boxes at :271 , 367
Line 6 of 11
Boxes at :544 , 205
Line 7 of 11
Boxes at :544 , 340
Line 8 of 11
Boxes at :544 , 475
Line 9 of 11
Boxes at :686 , 340
Line 10 of 11
Boxes at :686 , 475
Any suggestions/thoughts?
Thanks in advance
1