java - findviewbyid always returns null with imageview -
i have been struggling evening, whatever reason imageviews return null!
here java
package com.example.christmascontroller; import android.os.bundle; import android.app.activity; import android.app.alertdialog; import android.app.dialog; import android.content.dialoginterface; import android.util.log; import android.view.menu; import android.view.view; import android.view.view.onclicklistener; import android.view.window; import android.widget.imageview; public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { dialog dialog = new dialog(this, android.r.style.theme_translucent_notitlebar); dialog.requestwindowfeature(window.feature_no_title); super.oncreate(savedinstancestate); dialog.setcontentview(r.layout.activity_main); dialog.setcancelable(true); dialog.show(); imageview imgremote = (imageview) findviewbyid(r.id.control); imgremote.setclickable(true); imgremote.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { msbox("remote","you in remote"); //remote view open code } }); imageview imgplaylist = (imageview) findviewbyid(r.id.playlist); imgplaylist.setclickable(true); imgplaylist.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { log.w("myapp", "no network"); //play list view open code } }); imageview imgnew = (imageview) findviewbyid(r.id.seqnew); imgnew.setclickable(true); imgnew.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { msbox("new sequence","you in new sequence"); //new view open code } }); imageview imgmanual = (imageview) findviewbyid(r.id.manual); imgmanual.setclickable(true); imgmanual.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { msbox("manual","you in manual"); //manual view open code } }); imageview imgrefresh = (imageview) findviewbyid(r.id.refresh); imgrefresh.setclickable(true); imgrefresh.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { msbox("refresh","you in refresh"); //code pull refresh server } }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } protected void onstart() { } public void msbox(string str,string str2) { alertdialog.builder dlgalert = new alertdialog.builder(this); dlgalert.settitle(str); dlgalert.setmessage(str2); dlgalert.setpositivebutton("ok",new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { finish(); } }); dlgalert.setcancelable(true); dlgalert.create().show(); } }
here xml activity_main.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:background="#6698ff" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".mainactivity" > <imageview android:id="@+id/logo" android:layout_width="100dp" android:layout_height="40dp" android:layout_alignparenttop="true" android:layout_alignright="@+id/imageview1" android:contentdescription="@string/todo" android:src="@drawable/logo" /> <imageview android:id="@+id/control" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignleft="@+id/imageview03" android:layout_below="@+id/imageview03" android:contentdescription="@string/todo" android:src="@drawable/control" /> <imageview android:id="@+id/imageview3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/imageview1" android:layout_below="@+id/control" android:contentdescription="@string/todo" android:src="@drawable/line" /> <imageview android:id="@+id/playlist" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignleft="@+id/imageview3" android:layout_below="@+id/imageview3" android:contentdescription="@string/todo" android:src="@drawable/playlist" /> <imageview android:id="@+id/imageview02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/playlist" android:layout_below="@+id/playlist" android:contentdescription="@string/todo" android:src="@drawable/line" /> <imageview android:id="@+id/seqnew" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignleft="@+id/imageview02" android:layout_below="@+id/imageview02" android:contentdescription="@string/todo" android:src="@drawable/seqnew" /> <imageview android:id="@+id/imageview4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/seqnew" android:layout_below="@+id/seqnew" android:contentdescription="@string/todo" android:src="@drawable/line" /> <imageview android:id="@+id/manual" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignleft="@+id/imageview4" android:layout_below="@+id/imageview4" android:contentdescription="todo" android:src="@drawable/manual" tools:ignore="hardcodedtext" /> <imageview android:id="@+id/imageview04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/manual" android:layout_below="@+id/manual" android:contentdescription="todo" android:src="@drawable/line" tools:ignore="hardcodedtext" /> <imageview android:id="@+id/refresh" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignleft="@+id/imageview04" android:layout_below="@+id/imageview04" android:contentdescription="todo" android:src="@drawable/refresh" /> <imageview android:id="@+id/imageview1" android:layout_width="match_parent" android:layout_height="50dp" android:layout_below="@+id/logo" android:layout_centerhorizontal="true" android:contentdescription="@string/todo" android:gravity="right|center_vertical" android:scaletype="centerinside" android:src="@drawable/tree" tools:ignore="hardcodedtext" /> <imageview android:id="@+id/imageview03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/imageview1" android:layout_below="@+id/imageview1" android:layout_margintop="14dp" android:contentdescription="@string/todo" android:src="@drawable/line" /> </relativelayout>
thank in advance response. guess wants more detail.
my stack trace is:
08-30 18:21:11.682: e/androidruntime(1211): fatal exception: main 08-30 18:21:11.682: e/androidruntime(1211): process: com.example.christmascontroller, pid: 1211 08-30 18:21:11.682: e/androidruntime(1211): java.lang.runtimeexception: unable start activity componentinfo{com.example.christmascontroller/com.example.christmascontroller.mainactivity}: java.lang.nullpointerexception 08-30 18:21:11.682: e/androidruntime(1211): @ android.app.activitythread.performlaunchactivity(activitythread.java:2195) 08-30 18:21:11.682: e/androidruntime(1211): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2245) 08-30 18:21:11.682: e/androidruntime(1211): @ android.app.activitythread.access$800(activitythread.java:135) 08-30 18:21:11.682: e/androidruntime(1211): @ android.app.activitythread$h.handlemessage(activitythread.java:1196) 08-30 18:21:11.682: e/androidruntime(1211): @ android.os.handler.dispatchmessage(handler.java:102) 08-30 18:21:11.682: e/androidruntime(1211): @ android.os.looper.loop(looper.java:136) 08-30 18:21:11.682: e/androidruntime(1211): @ android.app.activitythread.main(activitythread.java:5017) 08-30 18:21:11.682: e/androidruntime(1211): @ java.lang.reflect.method.invokenative(native method) 08-30 18:21:11.682: e/androidruntime(1211): @ java.lang.reflect.method.invoke(method.java:515) 08-30 18:21:11.682: e/androidruntime(1211): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 08-30 18:21:11.682: e/androidruntime(1211): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 08-30 18:21:11.682: e/androidruntime(1211): @ dalvik.system.nativestart.main(native method) 08-30 18:21:11.682: e/androidruntime(1211): caused by: java.lang.nullpointerexception 08-30 18:21:11.682: e/androidruntime(1211): @ com.example.christmascontroller.mainactivity.onstart(mainactivity.java:43) 08-30 18:21:11.682: e/androidruntime(1211): @ android.app.instrumentation.callactivityonstart(instrumentation.java:1171) 08-30 18:21:11.682: e/androidruntime(1211): @ android.app.activity.performstart(activity.java:5241) 08-30 18:21:11.682: e/androidruntime(1211): @ android.app.activitythread.performlaunchactivity(activitythread.java:2168) 08-30 18:21:11.682: e/androidruntime(1211): ... 11 more
Comments
Post a Comment