java - Adding list to a list of lists doesn't work -


i can not code work. .txt file reading here: urls.txt

the problem code not @ add lines. whenever try @ "lists" gives me indexoutofboundsexception.

the code gets executed each 30 seconds, have call lists.clear(); method.

note: "lists" defined earlier:

    public static arraylist<arraylist<string>> lists = new arraylist<arraylist<string>>(); 

this code:

                try {                 url urls = new url("https://dl.dropboxusercontent.com/u/22001728/server%20creator/urls.txt");                 bufferedreader br = new bufferedreader(new inputstreamreader(urls.openstream()));                  lists.clear();                  string line;                 arraylist<string> list = new arraylist<string>();                  lists.add(list);                  int y = 0, z = 0;                  while ((line = br.readline()) != null) {                     y++;                     if(line.equalsignorecase(">")) {                         system.out.print("received command: insert ");                         lists.add(list);                         list.clear();                         z++;                         system.out.print(" ;  jumping " + z + "\n");                     } else {                         system.out.println("line: " + line + " added lists[" + z + "].");                         lists.get(z).add(line);                     }                 }                  int selectedindex = combomodel0.getindexof(combomodel0.getselecteditem());                 combomodel0.removeallelements();                  system.out.println("\n\n\n");                  system.out.println(lists.get(1).get(1));                  system.out.println("\n\n\n");              } catch (ioexception e) {                 system.out.println("failed download urls data.");             } 

you adding list collection of lists, clearing it. clear local variable, plus list in collection.

lists.add(list); list.clear(); 

you need create copy of list add collection.

lists.add(new arraylist<string>(list)); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -