java - displaying a Prepopulated database as a listview -
this question has answer here:
i trying display multiple columns of database inside listview. using sqliteasset helper , row.xml , main.xml. mainactivity extends listactivity. error i'm getting findviewbyid can't find linear layout "r.id.list" activity_main.xml has it.
this main class displays database info on list.
public class mainactivity extends listactivity { private cursor schedule; private mydatabase db; listview listview; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); db = new mydatabase(this); schedule = db.getschedule(); listview listview = (listview) findviewbyid(android.r.id.list); listview.setadapter(new simplecursoradapter( this, // context r.layout.row, // layout of row show db.getschedule(), // here cursor data // can new string[] {"fname", "ftype" }, // here tables show new int[] { android.r.id.text1, android.r.id.text2 }, // here show? ids // of layout elements put data. 0)); } @override protected void ondestroy() { super.ondestroy(); schedule.close(); db.close(); } }
row:
<textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginbottom="10dp" android:layout_margintop="10dp" android:text="textview" android:textcolor="#0000ff" android:textsize="25dp" /> <textview android:id="@+id/textview2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginbottom="10dp" android:layout_margintop="10dp" android:text="textview" android:textcolor="#0000ff" android:textsize="25dp" /> </linearlayout>
activity_main: (you can see id.list)
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <listview android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="fill_parent"> </listview> </linearlayout>
logcat:
12-02 01:04:44.436: e/androidruntime(1183): fatal exception: main 12-02 01:04:44.436: e/androidruntime(1183): process: com.example.mealplan, pid: 1183 12-02 01:04:44.436: e/androidruntime(1183): java.lang.runtimeexception: unable start activity componentinfo{com.example.mealplan/com.example.mealplan.mainactivity}: java.lang.runtimeexception: content must have listview id attribute 'android.r.id.list' 12-02 01:04:44.436: e/androidruntime(1183): @ android.app.activitythread.performlaunchactivity(activitythread.java:2195) 12-02 01:04:44.436: e/androidruntime(1183): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2245) 12-02 01:04:44.436: e/androidruntime(1183): @ android.app.activitythread.access$800(activitythread.java:135) 12-02 01:04:44.436: e/androidruntime(1183): @ android.app.activitythread$h.handlemessage(activitythread.java:1196) 12-02 01:04:44.436: e/androidruntime(1183): @ android.os.handler.dispatchmessage(handler.java:102) 12-02 01:04:44.436: e/androidruntime(1183): @ android.os.looper.loop(looper.java:136) 12-02 01:04:44.436: e/androidruntime(1183): @ android.app.activitythread.main(activitythread.java:5017) 12-02 01:04:44.436: e/androidruntime(1183): @ java.lang.reflect.method.invokenative(native method) 12-02 01:04:44.436: e/androidruntime(1183): @ java.lang.reflect.method.invoke(method.java:515) 12-02 01:04:44.436: e/androidruntime(1183): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 12-02 01:04:44.436: e/androidruntime(1183): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 12-02 01:04:44.436: e/androidruntime(1183): @ dalvik.system.nativestart.main(native method) 12-02 01:04:44.436: e/androidruntime(1183): caused by: java.lang.runtimeexception: content must have listview id attribute 'android.r.id.list' 12-02 01:04:44.436: e/androidruntime(1183): @ android.app.listactivity.oncontentchanged(listactivity.java:243) 12-02 01:04:44.436: e/androidruntime(1183): @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:293) 12-02 01:04:44.436: e/androidruntime(1183): @ android.app.activity.setcontentview(activity.java:1929) 12-02 01:04:44.436: e/androidruntime(1183): @ com.example.mealplan.mainactivity.oncreate(mainactivity.java:35) 12-02 01:04:44.436: e/androidruntime(1183): @ android.app.activity.performcreate(activity.java:5231) 12-02 01:04:44.436: e/androidruntime(1183): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1087) 12-02 01:04:44.436: e/androidruntime(1183): @ android.app.activitythread.performlaunchactivity(activitythread.java:2159)
change line :
android:id="@+id/list"
to
android:id="@id/android:list"
Comments
Post a Comment