java - findViewByIdlayoutinflator fails to inflate my layouts, returns null when using -
my main activity calls view inflate main.xml whatever reason seems return null, i'm kind of lost here since worked in 4.2 doesn't after upgrading rest of source 6.0
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); layoutinflater inflater = (layoutinflater) this.getsystemservice( context.layout_inflater_service); view layout = inflater.inflate(r.layout.main, null); setcontentview(layout); ctx = this; prefs = preferencemanager.getdefaultsharedpreferences(this); res = getresources(); maudiomanager = (audiomanager)getsystemservice(context.audio_service); mmediabuttonreceiver = new remotecontrolreceiver(); mediafilter = new intentfilter(intent.action_media_button); mediafilter.setpriority(integer.max_value); registerreceiver(mmediabuttonreceiver, mediafilter); //mdrawable = (this.res.getdrawable(r.drawable.glowy_metal)); //mbackground.setbackgrounddrawable(mdrawable); mbackground = (imageview) layout.findviewbyid(r.id.background); mbackground.setontouchlistener(new backgroundtouchlistener()); logcat shows null here:
mbackground = (imageview) layout.findviewbyid(r.id.background); the background id in main.xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <imageview android:id="@+id/background" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:scaletype="fitcenter" android:background="@drawable/glowy_metal"/> can shed insight might going on here?
logcat :
d/androidruntime(12906): shutting down vm e/androidruntime(12906): fatal exception: main e/androidruntime(12906): process: com.cphelps76.carhome, pid: 12906 e/androidruntime(12906): java.lang.runtimeexception: unable start activity componentinfo{com.cphelps76.carhome/com.cphelps76.carhome.carhomeactivity}: java.lang.nullpointerexception: attempt invoke virtual method 'void android.view.view.setontouchlistener(android.view.view$ontouchlistener)' on null object reference e/androidruntime(12906): @ android.app.activitythread.performlaunchactivity(activitythread.java:2356) e/androidruntime(12906): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2418) e/androidruntime(12906): @ android.app.activitythread.access$900(activitythread.java:154) e/androidruntime(12906): @ android.app.activitythread$h.handlemessage(activitythread.java:1321) e/androidruntime(12906): @ android.os.handler.dispatchmessage(handler.java:102) e/androidruntime(12906): @ android.os.looper.loop(looper.java:135) e/androidruntime(12906): @ android.app.activitythread.main(activitythread.java:5289) e/androidruntime(12906): @ java.lang.reflect.method.invoke(native method) e/androidruntime(12906): @ java.lang.reflect.method.invoke(method.java:372) e/androidruntime(12906): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:904) e/androidruntime(12906): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:699) e/androidruntime(12906): caused by: java.lang.nullpointerexception: attempt invoke virtual method 'void android.view.view.setontouchlistener(android.view.view$ontouchlistener)' on null object reference e/androidruntime(12906): @ com.cphelps76.carhome.carhomeactivity.oncreate(carhomeactivity.java:211) e/androidruntime(12906): @ android.app.activity.performcreate(activity.java:5990) e/androidruntime(12906): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1106) e/androidruntime(12906): @ android.app.activitythread.performlaunchactivity(activitythread.java:2309) e/androidruntime(12906): ... 10 more w/activitymanager( 789): force finishing activity 1 com.cphelps76.carhome/.carhomeactivity
just use
setcontentview(r.layout.main); and later
mbackground = (imageview) findviewbyid(r.id.background); no need create new inflater since activity has methods want.
Comments
Post a Comment