Android studio app keeps crashing: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' -
so practicing using list view , having @ several questions online, , trying make there 2 activities, 1 list view , user able add list, tried making:
activity 1
package com.example.nooli.listview; import android.app.listactivity; import android.content.intent; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.view; import android.widget.arrayadapter; import android.widget.button; import android.widget.edittext; import java.util.arraylist; public class mainactivity extends listactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); final arraylist<string> things2 = new arraylist<string>(); final arrayadapter<string> adapter = new arrayadapter<string>(getlistview().getcontext(),android.r.layout.simple_list_item_1,things2); getlistview().setadapter(adapter); button add = (button)findviewbyid(r.id.button); add.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent setnew = new intent(getapplicationcontext(),main2activity.class); } }); button newb = (button)findviewbyid(r.id.button2); final edittext et = (edittext)findviewbyid(r.id.edittext); newb.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { things2.add(string.valueof(et.gettext())); arrayadapter<string> adapter = new arrayadapter<string>(getlistview().getcontext(),android.r.layout.simple_list_item_1,things2); getlistview().setadapter(adapter); } }); } }
activity 2
package com.example.nooli.listview; import android.content.intent; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.view; import android.widget.button; public class main2activity extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main2); button b = (button)findviewbyid(r.id.button2); b.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent = new intent(getapplicationcontext(),mainactivity.class); startactivity(i); } }); } }
activity 1 xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 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="com.example.nooli.listview.mainactivity"> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button" android:textcolor="@android:color/white" android:background="@drawable/plus" android:text="+" android:layout_alignparentbottom="true" android:elevation="10dp" android:layout_alignright="@+id/list" android:layout_alignend="@+id/list" /> <listview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/list" android:choicemode="singlechoice" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" /> </relativelayout>
activity 2 xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 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="com.example.nooli.listview.main2activity"> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="make new" android:id="@+id/button2" android:layout_alignparentbottom="true" android:layout_centerhorizontal="true" android:layout_marginbottom="126dp" /> <edittext android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/edittext" android:layout_margintop="66dp" android:width="300dp" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" /> </relativelayout>
logcat
02-05 16:52:39.944 24684-24684/? e/zygote: mountemulatedstorage() 02-05 16:52:39.944 24684-24684/? e/zygote: v2 02-05 16:52:39.944 24684-24684/? i/libpersona: knox_sdcard checking 10211 02-05 16:52:39.944 24684-24684/? i/libpersona: knox_sdcard not persona 02-05 16:52:39.984 24684-24684/? i/selinux: function: selinux_compare_spd_ram, spd-policy existed. and_ver=sepf_sm-g900f_5.0 ver=27 02-05 16:52:39.984 24684-24684/? i/selinux: function: selinux_compare_spd_ram , priority [2] , priority version ve=sepf_sm-g900f_5.0-1_0032 02-05 16:52:39.984 24684-24684/? e/selinux: [debug] get_category: variable seinfo: default sensitivity: null, cateogry: null 02-05 16:52:39.984 24684-24684/? i/art: late-enabling -xcheck:jni 02-05 16:52:40.004 24684-24684/? d/timakeystoreprovider: timasignature unavailable 02-05 16:52:40.004 24684-24684/? d/activitythread: added timakeystore provider 02-05 16:52:40.054 24684-24684/com.example.nooli.listview d/resourcesmanager: creating new assetmanager , set /data/app/com.example.nooli.listview-2/base.apk 02-05 16:52:40.174 24684-24684/com.example.nooli.listview d/abslistview: motionrecognitionmanager 02-05 16:52:40.174 24684-24684/com.example.nooli.listview d/androidruntime: shutting down vm 02-05 16:52:40.174 24684-24684/com.example.nooli.listview e/androidruntime: fatal exception: main process: com.example.nooli.listview, pid: 24684 java.lang.runtimeexception: unable start activity componentinfo{com.example.nooli.listview/com.example.nooli.listview.mainactivity}: java.lang.runtimeexception: content must have listview id attribute 'android.r.id.list' @ android.app.activitythread.performlaunchactivity(activitythread.java:2658) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2723) @ android.app.activitythread.access$900(activitythread.java:172) @ android.app.activitythread$h.handlemessage(activitythread.java:1422) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:145) @ android.app.activitythread.main(activitythread.java:5832) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1399) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1194) caused by: java.lang.runtimeexception: content must have listview id attribute 'android.r.id.list' @ android.app.listactivity.oncontentchanged(listactivity.java:243) @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:432) @ android.app.activity.setcontentview(activity.java:2241) @ com.example.nooli.listview.mainactivity.oncreate(mainactivity.java:19) @ android.app.activity.performcreate(activity.java:6221) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1119) @ android.app.activitythread.performlaunchactivity(activitythread.java:2611) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2723) @ android.app.activitythread.access$900(activitythread.java:172) @ android.app.activitythread$h.handlemessage(activitythread.java:1422) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:145) @ android.app.activitythread.main(activitythread.java:5832) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1399) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1194)
first of all, way debug android app crash first @ last "cause" of crash. in case
caused by: java.lang.runtimeexception: content must have listview id attribute 'android.r.id.list'
from here search on crash message, i.e. your content must have listview id attribute 'android.r.id.list'
if google search it, you'll find same question asked in your content must have listview id attribute 'android.r.id.list' best answer in https://stackoverflow.com/a/11050829/3286489.
hence answer question convert listview id
<listview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/list" android:choicemode="singlechoice" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" />
to
<listview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@android:id/list" android:choicemode="singlechoice" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" />
hope helps future bug hunt , search android solution. cheers!
Comments
Post a Comment