We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Help...Java.lang error ArrayIndexOutOfBoundsExcept
Page Index Toggle Pages: 1
Help...Java.lang error ArrayIndexOutOfBoundsExcept (Read 1939 times)
Help...Java.lang error ArrayIndexOutOfBoundsExcept
Oct 16th, 2009, 4:59pm
 
Error copied here- starts at line:  data[0][i][1] = lst[1];
in code copied below... I'm using a MaxOSX 10.5.8
and Processing )135 Beta

Error:------------------------------------------------------------
java.lang.ArrayIndexOutOfBoundsException: 1
     at Temporary_1237_5347.numData(Temporary_1237_5347.java:176)
     at Temporary_1237_5347.draw(Temporary_1237_5347.java:59)
     at processing.core.PApplet.handleDisplay(PApplet.java:1465)
     at processing.core.PGraphics.requestDisplay(PGraphics.java:690)
     at processing.core.PApplet.run(PApplet.java:1562)
     at java.lang.Thread.run(Thread.java:552)

java.lang.ArrayIndexOutOfBoundsException: 1
     at Temporary_1237_5347.numData(Temporary_1237_5347.java:176)
     at Temporary_1237_5347.draw(Temporary_1237_5347.java:59)
     at processing.core.PApplet.handleDisplay(PApplet.java:1465)
     at processing.core.PGraphics.requestDisplay(PGraphics.java:690)
     at processing.core.PApplet.run(PApplet.java:1562)
     at java.lang.Thread.run(Thread.java:552)

Code:--------------------------------
}
 //fill array
 //println("there are " + datalength[0] + " earthquakes in the last hour.");
 for(int i=1;i<lineshour.length;i++){
   String dat = lineshour[i];
   String lst[] = split(dat,',');
   data[0][i][0] = lst[0];
   data[0][i][1] = lst[1];
   data[0][i][2] = lst[2];
   data[0][i][3] = lst[3]+lst[4];
   data[0][i][4] = lst[5];
   data[0][i][5] = lst[6];
   data[0][i][6] = lst[7];
   data[0][i][7] = lst[8];
   data[0][i][8] = lst[9];
   //println(i + " : lat " + data[0][i][4] + " ,  lon " + data[0][i][5] + " ,  mag " + data[0][i][6]);
 }

 for(int i=1;i<linesday.length;i++){
   String dat = linesday[i];
   String lst[] = split(dat,',');
   data[1][i][0] = lst[0];
   data[1][i][1] = lst[1];
   data[1][i][2] = lst[2];
   data[1][i][3] = lst[3]+lst[4];
   data[1][i][4] = lst[5];
   data[1][i][5] = lst[6];
   data[1][i][6] = lst[7];
   data[1][i][7] = lst[8];
   data[1][i][8] = lst[9];
 }
 for(int i=1;i<lines7days.length;i++){
   String dat = lines7days[i];
   String lst[] = split(dat,',');
   data[2][i][0] = lst[0];
   data[2][i][1] = lst[1];
   data[2][i][2] = lst[2];
   data[2][i][3] = lst[3]+lst[4];
   data[2][i][4] = lst[5];
   data[2][i][5] = lst[6];
   data[2][i][6] = lst[7];
   data[2][i][7] = lst[8];
   data[2][i][8] = lst[9];
 }
}

void flashingLoadText() {
 if (frameCount%10 < 5) {
   fill(0);
 }
 else {
   fill(100);
 }
 textFont(font_loading);
 text("Loading New Data...",width/2-50,height/2);
 if (frameCount%10 < 5) {
   fill(255);
 }
 else {
   fill(0);
 }
 text("Loading New Data...",width/2-53,height/2-3);
}

void keyPressed() {
 if (key == ' ') {
   println("manual update...");
   mode = 1;
   counter = 0;
   runcounter = 0;
 }
}

void mousecoords(){
 fill(0);
 rect(900,0,955,40);
 fill(255);
 text(mouseX,900,20);
 text(mouseY,900,40);
}
---------
Console Message is:
17/10/09 12:39:59 PM [0x0-0x326326].org.processing.app[40332] java.lang.ArrayIndexOutOfBoundsException: 1
17/10/09 12:39:59 PM [0x0-0x326326].org.processing.app[40332]  at Temporary_1237_5347.numData(Temporary_1237_5347.java:176)
17/10/09 12:39:59 PM [0x0-0x326326].org.processing.app[40332]  at Temporary_1237_5347.draw(Temporary_1237_5347.java:59)
17/10/09 12:39:59 PM [0x0-0x326326].org.processing.app[40332]  at processing.core.PApplet.handleDisplay(PApplet.java:1465)
17/10/09 12:39:59 PM [0x0-0x326326].org.processing.app[40332]  at processing.core.PGraphics.requestDisplay(PGraphics.java:690)
17/10/09 12:39:59 PM [0x0-0x326326].org.processing.app[40332]  at processing.core.PApplet.run(PApplet.java:1562)
17/10/09 12:39:59 PM [0x0-0x326326].org.processing.app[40332]  at java.lang.Thread.run(Thread.java:552)
17/10/09 12:39:59 PM [0x0-0x326326].org.processing.app[40332] java.lang.ArrayIndexOutOfBoundsException: 1
17/10/09 12:39:59 PM [0x0-0x326326].org.processing.app[40332]  at Temporary_1237_5347.numData(Temporary_1237_5347.java:176)
17/10/09 12:39:59 PM [0x0-0x326326].org.processing.app[40332]  at Temporary_1237_5347.draw(Temporary_1237_5347.java:59)
17/10/09 12:39:59 PM [0x0-0x326326].org.processing.app[40332]  at processing.core.PApplet.handleDisplay(PApplet.java:1465)
17/10/09 12:39:59 PM [0x0-0x326326].org.processing.app[40332]  at processing.core.PGraphics.requestDisplay(PGraphics.java:690)
17/10/09 12:39:59 PM [0x0-0x326326].org.processing.app[40332]  at processing.core.PApplet.run(PApplet.java:1562)
17/10/09 12:39:59 PM [0x0-0x326326].org.processing.app[40332]  at java.lang.Thread.run(Thread.java:552)
17/10/09 12:39:59 PM [0x0-0x326326].org.processing.app[40332]  at java.lang.Thread.run(Thread.java:552)

Thanks for looking at it for me;)))
Re: Help...Java.lang error ArrayIndexOutOfBoundsExcept
Reply #1 - Oct 17th, 2009, 8:13am
 
First, you are on the wrong forum: Processing Implementations is for "Questions about Processing in Ruby, Python, JavaScript, ActionScript, Scala, etc. " while you seem to use good old Processing (still at 0135? that's old already... Smiley)

Second, well, it means that lst is an array with only one entry. Since it comes from a split, I suppose it means your line 'dat' has no comma inside. Do a println before the split to ensure that.
Re: Help...Java.lang error ArrayIndexOutOfBoundsExcept
Reply #2 - Oct 17th, 2009, 5:47pm
 
Can u cut and paste the correction as an example... I'm not getting it...

thanks
Re: Help...Java.lang error ArrayIndexOutOfBoundsExcept
Reply #3 - Oct 19th, 2009, 2:45am
 
There is no correction, it depends on your input data.
You do:
String dat = lineshour[i];
String lst[] = split(dat,',');

replace with:
String dat = lineshour[i];
println(dat);
String lst[] = split(dat,',');

and see if there are commas inside the displayed line. If not, you found your problem.
Page Index Toggle Pages: 1