Friday, 15 July 2011

arrays - Java 2D ArrayList -



arrays - Java 2D ArrayList -

so every time run programme , come in 2nd choice, tells me rangecheck error , index0 , size 0.

what understand after research arraylist empty, how utilize add together function in 2d arraylist?

|abcdefghijklmnopqrstuvwx

--+------------------------

01|gggggggggggggggggggggggg

02|gggggggggggggggggggggggg

03|gggggggggggggggggggggggg

04|gggyyyyyyyyyyyyyyyyyyggg

05|gggyggggggggggggggggyggg

06|gggyggggggggggggggggyggg

07|gggyggyyyyyyyyyyyyggyggg

08|gggyggyggggggggggyggyggg

09|gggyyyyggggggggggyyyyggg

10|gggggggggggggggggggggggg

11|gggggggggggggggggggggggg

12|gggggggggggggggggggggggg

package map; import java.io.fileinputstream; import java.io.inputstream; import java.util.scanner; import java.util.arraylist; public class mapmain { public static void main(string [ ] args) { scanner input = new scanner(system.in); inputstream = null; int i; char c; string t; arraylist<arraylist<string>> contain = new arraylist<arraylist<string>>(); for(int l = 0; l < 30; l++) { contain.add(new arraylist<string>()); } try{ do{ int a=0; string elements; system.out.print("to load map come in 1\nto print loded map come in 2\nto alter specific elements press 3 "); a=input.nextint(); switch (a){ case 1 : system.out.print("what file dest?"); t=input.nextline(); = new fileinputstream(t); while((i=is.read())!=-1) { c=(char)i; string o = "ankosh"; //contain.add(contain.o); } break; case 2: while(true) { string u = contain.get(16).get(0); //system.out.print(contain); break; } break; case 3: system.out.print("what want insert?"); elements=input.nextline(); //switch (elements){ //case } break; } while(true); }catch(exception e){ // if i/o error occurs e.printstacktrace(); }finally{ } } }

you created array of arrays, , arrays contains, far it's ok. now, on case 2 trying reach first element of 16th array (basically of type string) null since didn't add together yet array. need before trying get(index), check length of array bigger index. in order add together array:content.get(16).add(str);.

java arrays arraylist

No comments:

Post a Comment