java - IllegalStateException occurring when similar code doesn't create the error -


so wrote 2 code fragments 1 works intended , other generates , illegalstateexception error when both me should exact same thing. why getting , error 1 using gamescreen object. gamescreen object code should return identical content working code. clueless why doesn't work.

working code:

public void begin(view view) {          class<?>[] cls = new class<?>[5];         cls[0]=quicktouchactivity.class;         cls[1]=longtouchactivity.class;         cls[2]=middletouchactivity.class;         cls[3]=lefttouchactivity.class;         cls[4]=righttouchactivity.class;         random r= new random();           intent intent = new intent(this, cls[r.nextint(cls.length)]);         startactivity(intent);    } 

error code:

public void begin(view view) {       gamescreen g = new gamescreen();         intent intent = new intent(this, g.getrandomscreen());         startactivity(intent); } 
import java.util.random;  public class gamescreen  { private class<?>[] cls;  public gamescreen() {     cls= new class<?>[5];     class<?>[] cls = new class<?>[5];     cls[0]=quicktouchactivity.class;     cls[1]=longtouchactivity.class;     cls[2]=middletouchactivity.class;     cls[3]=lefttouchactivity.class;     cls[4]=righttouchactivity.class; }  public class<?> getrandomscreen() {     random r= new random();     return cls[r.nextint(cls.length)]; }  } 

logcat:

05-21 19:09:03.849: e/androidruntime(361): fatal exception: main 05-21 19:09:03.849: e/androidruntime(361): java.lang.illegalstateexception: not execute method of activity 05-21 19:09:03.849: e/androidruntime(361):  @ android.view.view$1.onclick(view.java:2704) 05-21 19:09:03.849: e/androidruntime(361):  @ android.view.view.performclick(view.java:3100) 05-21 19:09:03.849: e/androidruntime(361):  @ android.view.view$performclick.run(view.java:11644) 05-21 19:09:03.849: e/androidruntime(361):  @ android.os.handler.handlecallback(handler.java:587) 05-21 19:09:03.849: e/androidruntime(361):  @ android.os.handler.dispatchmessage(handler.java:92) 05-21 19:09:03.849: e/androidruntime(361):  @ android.os.looper.loop(looper.java:126) 05-21 19:09:03.849: e/androidruntime(361):  @ android.app.activitythread.main(activitythread.java:3997) 05-21 19:09:03.849: e/androidruntime(361):  @ java.lang.reflect.method.invokenative(native method) 05-21 19:09:03.849: e/androidruntime(361):  @ java.lang.reflect.method.invoke(method.java:491) 05-21 19:09:03.849: e/androidruntime(361):  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:841) 05-21 19:09:03.849: e/androidruntime(361):  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:599) 05-21 19:09:03.849: e/androidruntime(361):  @ dalvik.system.nativestart.main(native method) 05-21 19:09:03.849: e/androidruntime(361): caused by: java.lang.reflect.invocationtargetexception 05-21 19:09:03.849: e/androidruntime(361):  @ java.lang.reflect.method.invokenative(native method) 05-21 19:09:03.849: e/androidruntime(361):  @ java.lang.reflect.method.invoke(method.java:491) 05-21 19:09:03.849: e/androidruntime(361):  @ android.view.view$1.onclick(view.java:2699) 05-21 19:09:03.849: e/androidruntime(361):  ... 11 more 05-21 19:09:03.849: e/androidruntime(361): caused by: java.lang.nullpointerexception 05-21 19:09:03.849: e/androidruntime(361):  @ android.content.componentname.<init>(componentname.java:76) 05-21 19:09:03.849: e/androidruntime(361):  @ android.content.intent.<init>(intent.java:2840) 05-21 19:09:03.849: e/androidruntime(361):  @ com.example.worldshardestgame.home.begin(home.java:41) 05-21 19:09:03.849: e/androidruntime(361):  ... 14 more 

is because declaring 2 different cls variables in gamescreen constructor? 1 instance field should sufficient. don't know why delcaring both generate illegal state exception, perhaps issue.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -