i reading csv file. 1 of requirements check if column has value or not. in case want check value in array[18]. however, getting
exception in thread "main" java.lang.arrayindexoutofboundsexception: 18 is there other way check array index if has value or empty?
my code:
while ((scurrentline = br.readline())!= null) { string[] record = scurrentline.split(","); if(record.length > 0){ // checking if current line not empty on file if(record[18] != null){ // per console, getting error in line string readdaterecord = record[18]; // other processing here } } }
look, according javase7:
arrayindexoutofboundsexception thrown indicate array has been accessed illegal index. (in case) index greater or equal size of array.
means, index 18 not legal array record in code. if array record null exception called nullpointerexception.
to overcome problem, there many solutions, 1 can be
//assuming record initialized if(record.length > 18){ string readdaterecord = record[18]; ... }
Comments
Post a Comment