• Post Reply Bookmark Topic Watch Topic
  • New Topic

OutOfBoundsException  RSS feed

 
Gregory Thomas
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am reading a csv file and I am coming with this error: java.lang.ArrayIndexOutOfBoundsException.

my csv file has these values

A, TEST1, TEST11,
A, TEST2, TEST22,
A, TEST3, TEST33,
A, TEST4, TEST44, TEST444



If the last string is blank (like the first 3 records), how could I eliminate the error in my code (without modifying the csv file) and process the next record? Thanks for any help.

Gregory
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, after the split(), you could check tokens.length. If it's less than four, you could just use "continue" to skip to the next iteration of the loop. YOu may, though, want to report an error in the file format if there are, say, only 1, 2, or 3 tokens, and just continue only if there are actually 0 tokens.
 
Gregory Thomas
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest! It helped.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!