Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java exception error explanation  RSS feed

 
Bob Matthews
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I run thru a large java program with 7 iterations - one for each different weka classifier
The first time round - in initialization process I write out to 7 models named model[01], model [11].....model[61]
All good

The second time around - we have a choice of either reading from Model[j1] or writing to Model [j1] where j is from 0 to 6, as before
BUT it only gets to the end of iteration j=0 when I get the following error

read from Model [01]
java.lang.ArrayIndexOutOfBoundsException: 2

What does the 2 refer to ?

Bob M
 
Junilu Lacar
Sheriff
Posts: 11146
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It refers to the value of the index that caused the exception. You tried to access the third element (index = 2) of an array that didn't have third element.
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The number is usually the index you are trying to read; you are obviously trying to read myArray[2] when that array has < 3 elements.
 
Skye Antinozzi
Ranch Hand
Posts: 68
3
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're having trouble finding where the exception is being thrown then I recommend doing a hand trace or stepping through with a debugger.
 
Junilu Lacar
Sheriff
Posts: 11146
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Skye Antinozzi wrote:If you're having trouble finding where the exception is being thrown then I recommend doing a hand trace or stepping through with a debugger.

The stack trace will usually tell you where the exception occurred, down to the source line number.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!