• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Array out of bounds exception .split()

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 55
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic