简体   繁体   English

Logcat错误内容必须具有ID属性为'android.R.id.list'的ListView

[英]Logcat error-Content must have a ListView whose id attribute is 'android.R.id.list'

My list view is showing error like this what i mention in my question,eventhough i mention in mainactivity extends listactivity also and my layout i put as listview 我的列表视图显示了这样的错误,我在问题中提到了这个问题,尽管我在mainactivity中提到的也扩展了listactivity,并且我的布局也作为listview

activity_list_item.xml activity_list_item.xml

<LinearLayout 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"
    tools:context=".MainActivity" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent" >
    </ListView>

</LinearLayout>

Mainactivity.java Mainactivity.java

public class MainActivity extends ListActivity implements FetchDataListener{
    private ProgressDialog dialog;

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

    private void initView() {
        // show progress dialog
        dialog = ProgressDialog.show(this, "", "Loading...");

        String url = "http://10.0.2.2/test/apps.php";
        FetchDataTask task = new FetchDataTask(this);
        task.execute(url);
    }

    @Override
    public void onFetchComplete(List<Application> data) {
        // dismiss the progress dialog
        if(dialog != null)  dialog.dismiss();
        // create new adapter
        ApplicationAdapter adapter = new ApplicationAdapter(this, data);
        // set the adapter to list
        setListAdapter(adapter);        
    }

    @Override
    public void onFetchFailure(String msg) {
        // dismiss the progress dialog
        if(dialog != null)  dialog.dismiss();
        // show failure message
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();        
    }
}

My log cat error is showing like this 我的日志猫错误显示如下

5-17 11:30:30.649: E/AndroidRuntime(1177): FATAL EXCEPTION: main
05-17 11:30:30.649: E/AndroidRuntime(1177): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jsonandroid/com.example.jsonandroid.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.os.Looper.loop(Looper.java:137)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.ActivityThread.main(ActivityThread.java:5039)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at java.lang.reflect.Method.invokeNative(Native Method)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at java.lang.reflect.Method.invoke(Method.java:511)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at dalvik.system.NativeStart.main(Native Method)
05-17 11:30:30.649: E/AndroidRuntime(1177): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.ListActivity.onContentChanged(ListActivity.java:243)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.Activity.setContentView(Activity.java:1881)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at com.example.jsonandroid.MainActivity.onCreate(MainActivity.java:17)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.Activity.performCreate(Activity.java:5104)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-17 11:30:30.649: E/AndroidRuntime(1177):     ... 11 more

您只需要将activity_list_item.xml中的列表视图ID更改为@android:id / list,如果您使用ListActivity,则listview ID必须像上面提到的那样

Change your layout to, 将布局更改为

    <?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

Remove the call to setContentView . 删除对setContentView的调用。

ListActivity does not require that you assign a layout to it via the setContentView() method, if you only want to show a ListView ListActivity contains by default a ListView. 如果仅想显示ListView,则ListActivity不需要通过setContentView()方法为其分配布局。ListActivity默认情况下包含ListView。

In case you need to include more Views than a ListView in your ListActivity you can still assign a layout to your activity. 万一您需要在ListActivity中包含比ListView多的View,您仍然可以为活动分配布局。 In this case your layout must contain a ListView with the android:id attribute set to @android:id/list . 在这种情况下,您的布局必须包含一个ListView,并将android:id属性设置为@android:id/list

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 您的内容必须具有ID属性为“ android.R.id.list”错误的ListView - Your content must have a ListView whose id attribute is 'android.R.id.list' error Android:内容必须有一个 id 属性为 &#39;android.R.id.list 的 ListView - Android: Content must have a ListView whose id attribute is 'android.R.id.list ListFragment:运行时错误“您的内容必须具有ID属性为&#39;android.R.list&#39;的ListView - ListFragment: Runtime error "Your content must have a ListView whose id attribute is 'android.R.list' FATAL EXCEPTION:main java.lang.RuntimeException:Content具有id属性&#39;android.R.id.list&#39;的视图,它不是ListView类 - FATAL EXCEPTION: main java.lang.RuntimeException: Content has view with id attribute 'android.R.id.list' that is not a ListView class Android Listview质疑``android.R.id.list&#39;&#39; - Android Listview questioned 'android.R.id.list' Android android.R.id.list ListView Fragment异常 - Android android.R.id.list ListView Fragment Exception 在ListFragment中找不到ListView&#39;android.R.id.list&#39; - ListView 'android.R.id.list' is not found in ListFragment 扩展ListActivity android.R.id.list - Extending ListActivity android.R.id.list 为什么我会收到“您的 TabHost 必须有一个 TabWidget,其 id 属性为‘android.R.id.tabs’”错误? - Why do I get an "Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabs'" error? Android必须具有ID为的Expandableview - Android must have Expandableview whose id is
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM