java - variable may have not been initialized? -
so in while loop print elements of arraylist store. afterwards when call it, says array may have not been initialized.
any thoughts? i'm trying read file of lines. each line has @ least 8 elements, , i'm sure array not empty because printed in while loop.
?
public class readerfile { public static scanner input; public static scanner input2; /** * @param args command line arguments */ public static void main(string[] args) { int count=0; arraylist<team> store; arraylist<robot> store2; //robot robot; string filelocation = "tourney2teams.csv"; string filelocation2 = "tourney1robots.csv"; try{ input = new scanner(new file(filelocation)).usedelimiter(","); } catch (ioexception ioexception) { system.out.print("problem"); } try { input2 = new scanner(new file (filelocation2)).usedelimiter(","); } catch (ioexception ioexception) { system.out.print("problem robot"); } try{ input.nextline(); system.out.print("please\n"); int countt = 0; while(input.hasnext()) { //int countt = 0; int id = input.nextint(); string teamname = input.next(); string coachfirst = input.next(); string coachlast = input.next(); string mentorfirst = input.next(); string mentorlast = input.next(); string teamfs = input.next(); string teamss = input.next(); input.nextline(); store = new arraylist<>(); team team = new team (teamname, id, coachfirst, coachlast,mentorfirst,mentorlast,teamfs,teamss); store.add(team); system.out.print("team numer"+store.get(0).teamnumber+"\n"); countt = countt+1; system.out.print("\n"+countt); } } catch (nosuchelementexception statexcemtion) { system.out.print("\nankosh"); } string x = store.get(2).teamname; } }
store = new arraylist<>();
this line reinitializes store @ every pass in while
. want initialize before while
accumulate while looping.
it says not initialized because reason never executed while loop (empty input).
Comments
Post a Comment