HY。
我的startactivity应该是ListActivity。
public class Main extends ListActivity
布局:
<?xml version="1.0" encoding="utf-8"?>
<ListView android:id="@+id/listView1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"></ListView>
每次我启动应用程序时都会崩溃。
请帮忙
日志:
09-22 16:37:35.115: ERROR/AndroidRuntime(349): Uncaught handler: thread main exiting due to uncaught exception
09-22 16:37:35.129: ERROR/AndroidRuntime(349): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.korn.pizzacounter/com.korn.pizzacounter.Main}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
09-22 16:37:35.129: ERROR/AndroidRuntime(349): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
09-22 16:37:35.129: ERROR/AndroidRuntime(349): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
09-22 16:37:35.129: ERROR/AndroidRuntime(349): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
09-22 16:37:35.129: ERROR/AndroidRuntime(349): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
09-22 16:37:35.129: ERROR/AndroidRuntime(349): at android.os.Handler.dispatchMessage(Handler.java:99)
09-22 16:37:35.129: ERROR/AndroidRuntime(349): at android.os.Looper.loop(Looper.java:123)
09-22 16:37:35.129: ERROR/AndroidRuntime(349): at android.app.ActivityThread.main(ActivityThread.java:4363)
09-22 16:37:35.129: ERROR/AndroidRuntime(349): at Your content must have a ListView whose id attribute is 'android.R.id.list'
答案 0 :(得分:2)
如果是ListActivity,则必须按以下方式调用默认列表:
<ListView android:id="@android:id/list"
请参阅开发人员文档 http://developer.android.com/reference/android/app/ListActivity.html
答案 1 :(得分:0)
使用此android:id="@android:id/listView1
代替android:id="@+id/listView1
如果你的listactivity必须像这样声明id
答案 2 :(得分:0)
at Your content must have a ListView whose id attribute is 'android.R.id.list'
如果要扩展ListActivity,则不应使用setContentView(R.layout.main)
。
所以从代码中删除setContentView(R.layout.main)。