android - Changing setConetentView with setOnClickListener causes program to crash (NullPointerException) -
so program worked fine until wanted added "mainmenu". want press button on mainmenu , make go "start_board", basicly made new. if don't give enough information please inform me, i'm new programming.
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.mainmenu); button splaybutton = (button) findviewbyid(r.id.splay); splaybutton.setbackgroundcolor(color.transparent); splaybutton.setonclicklistener(new view.onclicklistener(){ public void onclick(view v) { setcontentview(r.layout.start_board); //code, code , more code } }); }
mainmenu xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/mainmenu" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/mainmenu" > <button android:id="@+id/splay" android:layout_width="195dp" android:layout_height="64dp" android:layout_centervertical="true" android:layout_centerhorizontal="true" /> </relativelayout>
logcat
11-12 11:41:21.272: e/androidruntime(22244): fatal exception: main 11-12 11:41:21.272: e/androidruntime(22244): process: com.gerfort.gerfortrps, pid: 22244 11-12 11:41:21.272: e/androidruntime(22244): java.lang.nullpointerexception 11-12 11:41:21.272: e/androidruntime(22244): @ com.gerfort.gerfortrps.mainactivity$4.onclick(mainactivity.java:185) 11-12 11:41:21.272: e/androidruntime(22244): @ android.view.view.performclick(view.java:4637) 11-12 11:41:21.272: e/androidruntime(22244): @ android.view.view$performclick.run(view.java:19422) 11-12 11:41:21.272: e/androidruntime(22244): @ android.os.handler.handlecallback(handler.java:733) 11-12 11:41:21.272: e/androidruntime(22244): @ android.os.handler.dispatchmessage(handler.java:95) 11-12 11:41:21.272: e/androidruntime(22244): @ android.os.looper.loop(looper.java:136) 11-12 11:41:21.272: e/androidruntime(22244): @ android.app.activitythread.main(activitythread.java:5586) 11-12 11:41:21.272: e/androidruntime(22244): @ java.lang.reflect.method.invokenative(native method) 11-12 11:41:21.272: e/androidruntime(22244): @ java.lang.reflect.method.invoke(method.java:515) 11-12 11:41:21.272: e/androidruntime(22244): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1268) 11-12 11:41:21.272: e/androidruntime(22244): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1084) 11-12 11:41:21.272: e/androidruntime(22244): @ dalvik.system.nativestart.main(native method)
any ideas? in advance!
use fragments
. , use transaction change current ui when user press on button
Comments
Post a Comment