java - How to solve ArrayIndexOutofBoundsException -
i split string, did not consider exception. error comes out. example, if string "2012-10-21,20:00:00,,"
here codes: string str = "2012-10-21,20:00:00,,"; string a[] = str.split(","); string timestamp = a[0] + "t" + a[1]; string temp = a[2]; system.out.println(timestamp); system.out.println(temp);
here error:
exception in thread "main" java.lang.arrayindexoutofboundsexception: 2
actually, a[2] null, don't know how deal problem. because in string array, recodes contains value of temp, such "2012-10-21,20:00:00,90,".
thank you.
split remove empty elements. need use 2 parameter version:
str.split(",",-1);
see here: java string split removed empty values
Comments
Post a Comment