android - indexOf cause java.lang.ArrayIndexOutOfBoundsException -


i have user list stored on file, when want add parameter user

arraylist<user> list = loadlistfromfile(); system.out.println("user list: "+ list);  //the user update user olduser = getcurrentuser(); system.out.println("current user: "+ olduser);  //update user receives user , update param , returns updated user user newuser = updateuser(olduser, "updateparam"); system.out.println("new user: "+ newuser);  //replace old user new 1 list.set(list.indexof(olduser), newuser); 

all prints returns correct values when invoke

list.set(list.indexof(olduser), newuser); 

the app crashes error

java.lang.arrayindexoutofboundsexception: length=12; index=-1 

this strange , cannot understand reason of issue, in addition list has 2 items (not 12).

how fix this?

indexof(olduser) returns -1 if olduser not found. in case, set(-1) throw arrayindexoutofboundsexception.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -