• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array out of bounds exception .split()

 
Rob Brew
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.

I don't get this, when i use string.split() on an array declared as having two values, i get the OutOfBoundsException:

 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Couple of things

You're "reading" file wrong. Read an IO tutorial such as this one.
You're not closing your resources properly.

The array might not have a size of 2 because it gets reassigned on line 9. Try printing the size of it before you use it.
 
N Sahni
Ranch Hand
Posts: 55
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At line 7 reader.toString() will invoke java Object's toString() and it won't give you file contents.
Hence, s.split("/") will always give you zero length string.

You need to go through the tutorial mentioned by Wouter and read file properly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic