ListActivity返回错误

时间:2013-09-12 09:13:13

标签: android listactivity

ListActivity对此代码的需求是什么,“不幸的是,app已停止”

&安培;请不要这样!

package com.example.app;

Imports............

public class Main extends ListActivity 
{

 @Override
 protected void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    }

    public void onListItemClick(ListView parent, View v,
        int position, long id)
 { }

}
  
    

>     09-12 00:52:51.373:D / AndroidRuntime(1871):关闭VM     09-12 00:52:51.373:W / dalvikvm(1871):threadid = 1:线程退出,未捕获异常(group = 0x409c01f8)     09-12 00:52:51.393:E / AndroidRuntime(1871):致命异常:主要     09-12 00:52:51.393:E / AndroidRuntime(1871):java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.rss / com.example.rss.Main}:java.lang.RuntimeException:Your content必须有一个ListView,其id属性为'android.R.id.list'     09-12 00:52:51.393:E / AndroidRuntime(1871):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)     09-12 00:52:51.393:E / AndroidRuntime(1871):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)     09-12 00:52:51.393:E / AndroidRuntime(1871):在android.app.ActivityThread.access $ 600(ActivityThread.java:123)     09-12 00:52:51.393:E / AndroidRuntime(1871):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1147)     09-12 00:52:51.393:E / AndroidRuntime(1871):在android.os.Handler.dispatchMessage(Handler.java:99)     09-12 00:52:51.393:E / AndroidRuntime(1871):在android.os.Looper.loop(Looper.java:137)     09-12 00:52:51.393:E / AndroidRuntime(1871):在android.app.ActivityThread.main(ActivityThread.java:4424)     09-12 00:52:51.393:E / AndroidRuntime(1871):at java.lang.reflect.Method.invokeNative(Native Method)     09-12 00:52:51.393:E / AndroidRuntime(1871):at java.lang.reflect.Method.invoke(Method.java:511)     09-12 00:52:51.393:E / AndroidRuntime(1871):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784)     09-12 00:52:51.393:E / AndroidRuntime(1871):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)     09-12 00:52:51.393:E / AndroidRuntime(1871):at dalvik.system.NativeStart.main(Native Method)     09-12 00:52:51.393:E / AndroidRuntime(1871):引起:java.lang.RuntimeException:您的内容必须有一个ListView,其id属性为'android.R.id.list'     09-12 00:52:51.393:E / AndroidRuntime(1871):在android.app.ListActivity.onContentChanged(ListActivity.java:243)     09-12 00:52:51.393:E / AndroidRuntime(1871):at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:254)     09-12 00:52:51.393:E / AndroidRuntime(1871):在android.app.Activity.setContentView(Activity.java:1835)     09-12 00:52:51.393:E / AndroidRuntime(1871):at com.example.rss.Main.onCreate(Main.java:26)     09-12 00:52:51.393:E / AndroidRuntime(1871):在android.app.Activity.performCreate(Activity.java:4465)     09-12 00:52:51.393:E / AndroidRuntime(1871):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)     09-12 00:52:51.393:E / AndroidRuntime(1871):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)     09-12 00:52:51.393:E / AndroidRuntime(1871):... 11更多

  

2 个答案:

答案 0 :(得分:0)

您必须将属性设置为ListView

android:id="@android:id/list"

另外,不要忘记在清单中注册您的活动

答案 1 :(得分:0)

由于您要扩展ListActivity,因此需要使用android:id="@android:id/list"的Listview。

如果你想使用@+id/lst_main,那么不要扩展ListActivity,只需扩展Activity。

您还需要使用适配器

来扩充列表视图