java - How I do fix with IlegalStateException? -


when run app , run option 10 (newboatlistactivity), app crashes. according log, caused java.lang.illegalstateexception. have feeling caused somewhere in if else statement. if know how fix this, please through code below:

public void createlist(view view) {     //declare references     boatlist boat_list;     boat newboat;     boat newboat2;     boat newboat3;     textview tv;     edittext et;     edittext et2;     string infilename;     string urlfile;     boolean file_problem = false;     scanner fsc = null;      //set references     et = (edittext) findviewbyid(r.id.edit_infile);      et2 = (edittext) findviewbyid(r.id.edit_urlfile);      tv = (textview) findviewbyid(r.id.text_main);      //get user input. allows user choose way file     infilename = et.gettext().tostring();     urlfile = et2.gettext().tostring();      //create new boat object     newboat = new boat();     newboat2 = new boat();     newboat3 = new boat();      //try access , open file in app's assets directory     //assetmanager assetmanager = getassets();     try     {         assetmanager assetmanager = getassets();         fsc = new scanner(assetmanager.open(infilename));          //show file opened , read         tv.settext("infile opened , read successfully!");          //close file         fsc.close();     }     catch(ioexception e)     {         tv.settext("error: file not exist!");         file_problem = true;     }      //if file exist in assets directory, read data ,      //input data values boat object     if(!file_problem)     {         string make = fsc.nextline();         newboat.setmake(make);          string regist = fsc.nextline();         newboat.setregi(regist);          int length = fsc.nextint();         fsc.nextline();         newboat.setlength(length);          int beam = fsc.nextint();         fsc.nextline();         newboat.setbeam(beam);          string fuel = fsc.nextline();         newboat.setfuel(fuel);          double price = fsc.nextdouble();         fsc.nextline();         newboat.setprice(price);          string pic_url = fsc.nextline();         newboat.setpicurl(pic_url);          string make2 = fsc.nextline();         newboat2.setmake(make2);          string regist2 = fsc.nextline();         newboat2.setregi(regist2);          int length2 = fsc.nextint();         fsc.nextline();         newboat2.setlength(length2);          int beam2 = fsc.nextint();         fsc.nextline();         newboat2.setbeam(beam2);          string fuel2 = fsc.nextline();         newboat2.setfuel(fuel2);          double price2 = fsc.nextdouble();         fsc.nextline();         newboat2.setprice(price2);          string pic_url2 = fsc.nextline();         newboat2.setpicurl(pic_url2);          string make3 = fsc.nextline();         newboat3.setmake(make3);          string regist3 = fsc.nextline();         newboat3.setregi(regist3);          int length3 = fsc.nextint();         fsc.nextline();         newboat3.setlength(length3);          int beam3 = fsc.nextint();         fsc.nextline();         newboat3.setbeam(beam3);          string fuel3 = fsc.nextline();         newboat3.setfuel(fuel3);          double price3 = fsc.nextdouble();         fsc.nextline();         newboat3.setprice(price3);          string pic_url3 = fsc.nextline();         newboat3.setpicurl(pic_url3);          //close file         fsc.close();     }      //access list     boat_list = boatlist.getinstance();      //erase existing items in boatlist , add new ones     boat_list.clear();      if(boat_list.isempty())     {         boat_list.add(boat_list.size(), newboat);         boat_list.add(boat_list.size(), newboat2);         boat_list.add(boat_list.size(), newboat3);     }  } //end of createlist 

you're reading file you've closed. don't close file until you're done it.

also, in future post full stack trace. gives lot of information makes debugging easier- line numbers , messages.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -