简体   繁体   English

FATAL EXCEPTION:main java.lang.RuntimeException:Content具有id属性'android.R.id.list'的视图,它不是ListView类

[英]FATAL EXCEPTION: main java.lang.RuntimeException: Content has view with id attribute 'android.R.id.list' that is not a ListView class

I'm trying to use a ListView in a fragment . 我正在尝试在片段中使用ListView But i get this Error: FATAL EXCEPTION: main java.lang.RuntimeException: Content has view with id attribute 'android.R.id.list' that is not a ListView class . 但我得到这个错误: 致命异常:主java.lang.RuntimeException:内容具有id属性'android.R.id.list'的视图,它不是ListView类
My Code: 我的代码:

My ListFragment: 我的ListFragment:

public class whitelist_list extends ListFragment {


    Context mContext;

    @Override
    public void onAttach(Activity activity) {
        mContext = activity;
        Log.i("Event", "onAttach called");
        super.onAttach(activity);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
                "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
                "Linux", "OS/2" };
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_list_item_1, values);
        setListAdapter(adapter);
        return inflater.inflate(R.layout.whitelist_content, container, false);
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        // Do something with the data
    }

}


whitelist_list newFragment = new whitelist_list();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, newFragment)
.commit();

Edit: Solution: Declare Listview with android:id="@id/android:list" 编辑:解决方案:使用android:id =“@ id / android:list”声明Listview

If you use a ListActivity/Fragment, the id for your ListView in your layout should be @android:id/list, so: In your whitelist_list.xml (whatever_activityname.xml) in your ListView change the id to android:id="@android:id/list" 如果使用ListActivity / Fragment,则布局中ListView的id应为@android:id / list,因此:在ListView中的whitelist_list.xml(whatever_activityname.xml)中将id更改为android:id =“@机器人:ID /列表”

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

I had this error a while back. 我有一段时间没有这个错误。 For some reason the XML for the layout had been modified so that one of the components had the wrong type. 由于某种原因,布局的XML已被修改,因此其中一个组件的类型错误。 Go into the xml and look for the 'android.R.id.list' that doesn't belong to that item. 进入xml并查找不属于该项目的'android.R.id.list'。 I don't know how it got changed, but I think perhaps that when using the GUI editor, I changed something to list that shouldn't have been. 我不知道它是如何改变的,但我想也许在使用GUI编辑器时,我改变了一些不应该的列表。 If you don't see it, post the layout 如果您没有看到它,请发布布局

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

相关问题 致命异常:主java.lang.RuntimeException: - FATAL EXCEPTION: Main java.lang.RuntimeException: Android:内容必须有一个 id 属性为 &#39;android.R.id.list 的 ListView - Android: Content must have a ListView whose id attribute is 'android.R.id.list Logcat错误内容必须具有ID属性为&#39;android.R.id.list&#39;的ListView - Logcat error-Content must have a ListView whose id attribute is 'android.R.id.list' 您的内容必须具有ID属性为“ android.R.id.list”错误的ListView - Your content must have a ListView whose id attribute is 'android.R.id.list' error Android android.R.id.list ListView Fragment异常 - Android android.R.id.list ListView Fragment Exception 致命异常:main java.lang.RuntimeException:无法启动活动 - FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity AndroidRuntime:致命异常:主要由:java.lang.RuntimeException引起 - AndroidRuntime: FATAL EXCEPTION: main Caused by: java.lang.RuntimeException 致命异常:main java.lang.RuntimeException:无法启动活动 - FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity Android Listview质疑``android.R.id.list&#39;&#39; - Android Listview questioned 'android.R.id.list' 线程“ main”中的异常java.lang.RuntimeException:无法构造应用程序实例:类View - Exception in thread “main” java.lang.RuntimeException: Unable to construct Application instance: class View
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM