• Post Reply Bookmark Topic Watch Topic
  • New Topic

Out of bound errors IO file?  RSS feed

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to read in a file that looks like this and add it to an arrayList:
1-2-3
1-2
1-2-4
I created a two variable called String v1[1], v2[2] and I'm trying to add the strings of the 2nd and third column to the arraylist.
I have already split the "-" and it works fine if the second line had a number in it.
However, I'm having trouble when it hits the second line. It keeps giving me an out of bound error. I tried using isEmpty() or isEqual() == ""; for that scenario but it still doesn't work. Any ideas please? Ty.

is there a way to check if v2[2] does not exist?
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Lonsky wrote:
is there a way to check if v2[2] does not exist?


Hint: Have you tried checking the length of the v2 array?

Henry
 
Mike Lonsky
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Mike Lonsky wrote:
is there a way to check if v2[2] does not exist?


Hint: Have you tried checking the length of the v2 array?

Henry


Yeah, still gives me Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
It's so strange. I have no idea what could be going on.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Lonsky wrote:
Yeah, still gives me Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
It's so strange. I have no idea what could be going on.


Show me how you check the length of the array... as checking the length of an array should never throw that exception.

Henry
 
Mike Lonsky
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Mike Lonsky wrote:
Yeah, still gives me Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
It's so strange. I have no idea what could be going on.


Show me how you check the length of the array... as checking the length of an array should never throw that exception.

Henry

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to show us more context -- because what you described in the first post, and the code you show, don't seem to be related.

... but I am going to speculate that the array is called splitter (and not v2 as you mentioned) ...



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