• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Out of bound errors IO file?

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
This one time, at bandcamp, I had relations with a tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic