exception - How can I fix java.lang.ExceptionInInitializerError? -
i writing game , in last phrase. going write load class when press load button, exception, caused null pointer.
however, allocated every object , arrays new
. moreover, have points non-static
volatile
.
this code:
class loadstate { private char[] mapx; int x=0, y=0; public loadstate()throws filenotfoundexception, ioexception { string line; (int i=0;i<10;i++) { gameplay.tm[i].start(); } } gameplay.t.start(); int flag=0; int m=0; bufferedreader fr=new bufferedreader(new filereader("save.txt")); while((line=fr.readline())!=null){ if(flag==0){ gameplay.me.name=line; } if (flag==1){ gameplay.tt.time=integer.parseint(line); } else if(flag==2){ gameplay.lvl=integer.parseint(line); } else if(flag==3){ gameplay.win=boolean.parseboolean(line); } else if(flag==4){ gameplay.mainlvl=boolean.parseboolean(line); } else if(flag==5){ gameplay.lvl1=boolean.parseboolean(line); } else if(flag==6){ gameplay.lvl2=boolean.parseboolean(line); } else if(flag==7){ gameplay.lvl3=boolean.parseboolean(line); } else if(flag>7&&flag<37){ if(flag%3==2){ x=integer.parseint(line); } if(flag%3==0){ y=integer.parseint(line); gameplay.monster[m].oldpos.setlocation(x, y); } if(flag%3==1){ gameplay.monster[m].existance=boolean.parseboolean(line); m++; } } else if(flag==37){ x=integer.parseint(line); } else if(flag==38){ y=integer.parseint(line); gameplay.me.oldpos.setlocation(x, y); } else if(flag==39){ gameplay.me.killed=integer.parseint(line); } else if(flag==40){ gameplay.me.health=integer.parseint(line); } else if(flag>40){ mapx=line.tochararray(); for(int i=0;i<map.length;i++){ map[flag-41][i]=integer.parseint(""+mapx[i]); } } flag++; } fr.close(); } } class gameplay extends jpanel implements actionlistener{ static boolean lvl1=true; static boolean lvl2=false; static boolean lvl3=false; static boolean mainlvl=false; static me me=new me(); static portal portal=new portal(); static shot shot=new shot(); static thread s; static keyboard keyboard=new keyboard(); static monster monster[]=new monster[10]; static boolean win; static thread tm[]=new thread[10]; static int score=1000; static timethread tt=new timethread(); static thread t=new thread(tt); static int time=0; jbutton btn=new jbutton("start"); jbutton btn1=new jbutton("stop"); jbutton btn2=new jbutton("fixer"); jlabel lbl=new jlabel("time :"); jlabel lbl1=new jlabel("score :"); jlabel lbl2=new jlabel("health :"); jlabel lbl3=new jlabel("assasins :"); /**/}
i call game play before load state.
Comments
Post a Comment