• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.ArrayIndexOutOfBoundsException: 1  RSS feed

 
Alen Grace
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not know what I did wrong.
Here is my code:
 
Jhon Gonzales
Greenhorn
Posts: 22
Java Linux PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That error occurred because there isn't an index 1 at tokens's array. you should check if the token's array have 4 elements before assign the value to the variables.
 
Alen Grace
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did a for loop, and verfied that the tokens array has 0 to 3 index.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the only cause of that error is if you access an array index that doesn't exist. You haven't told us where it happens, though, so maybe something else is going on. But if it's thrown by that code then the tokens array looks to be the only culprit. I'd suggest printing out each value of s as you loop through the input. Maybe it's OK in some cases but not others.
 
George Maravich
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there try checking the size of your array. Usually, ArrayIndexOutOfBoundsException is thrown to indicate that an array has been accessed with an illegal index.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:I'd suggest printing out each value of s as you loop through the input....

Totally agree:

@Alen: How about something like:
System.out.println("'" + s + "' has " + tokens.length + " tokens");
at line 3?

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!