简体   繁体   English

Android:内容必须有一个 id 属性为 'android.R.id.list 的 ListView

[英]Android: Content must have a ListView whose id attribute is 'android.R.id.list

I have tired every possible solution online (including Stackoverflow) to fix this error, however nothing works any help would be much appreciated.我已经厌倦了所有可能的在线解决方案(包括 Stackoverflow)来修复此错误,但是没有任何帮助,我们将不胜感激。

What is the Error?什么是错误?

java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' java.lang.RuntimeException: 您的内容必须有一个 id 属性为“android.R.id.list”的 ListView

Note: There is many answers on stack overflow and I have tired them all.注意:关于堆栈溢出有很多答案,我已经厌倦了它们。

What do I have in my Code?我的代码中有什么?

XML: XML:

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Framelayout to display Fragments -->
<FrameLayout
    android:id="@+id/frame_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        />


<!-- Listview to display slider menu -->

<ListView

    android:id="@android:id/list"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@color/list_divider"
    android:dividerHeight="1dp"        
    android:listSelector="@drawable/list_selector"
    android:background="@color/list_background"/>

Code:代码:

 @SuppressLint("NewApi") public class MainActivity extends FragmentActivity {

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

mDrawerList = (ListView) this.findViewById(android.R.id.list);

Anyone know how to fix this error?有谁知道如何解决这个错误?

Complete logcat report完整的 logcat 报告

09-19 14:53:00.376: E/MainActivity(28935): Error in creating fragment
09-19 14:53:00.387: D/AndroidRuntime(28935): Shutting down VM
09-19 14:53:00.394: E/AndroidRuntime(28935): FATAL EXCEPTION: main
09-19 14:53:00.394: E/AndroidRuntime(28935): Process: info.androidhive.slidingmenu, PID: 28935
09-19 14:53:00.394: E/AndroidRuntime(28935): java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.slidingmenu/info.androidhive.slidingmenu.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
09-19 14:53:00.394: E/AndroidRuntime(28935):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2314)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at android.app.ActivityThread.access$800(ActivityThread.java:148)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at android.os.Handler.dispatchMessage(Handler.java:102)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at android.os.Looper.loop(Looper.java:135)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at android.app.ActivityThread.main(ActivityThread.java:5312)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at java.lang.reflect.Method.invoke(Native Method)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at java.lang.reflect.Method.invoke(Method.java:372)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
09-19 14:53:00.394: E/AndroidRuntime(28935): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
09-19 14:53:00.394: E/AndroidRuntime(28935):    at android.support.v4.app.ListFragment.ensureList(ListFragment.java:344)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at android.support.v4.app.ListFragment.onViewCreated(ListFragment.java:145)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:941)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:556)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1243)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at android.app.Activity.performStart(Activity.java:5969)
09-19 14:53:00.394: E/AndroidRuntime(28935):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2277)
09-19 14:53:00.394: E/AndroidRuntime(28935):    ... 10 more

do not use android.R.id.list instead use R.id.list.不要使用 android.R.id.list 而是使用 R.id.list。
Sorry for previous half answer but @android:id/list is specific to ListActivity and ListFragment from documentation:抱歉之前的一半答案,但 @android:id/list 特定于文档中的 ListActivity 和 ListFragment:

ListActivity has a default layout that consists of a single, full-screen list in the center of the screen. ListActivity 有一个默认布局,它由屏幕中央的单个全屏列表组成。 However, if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate().但是,如果您愿意,您可以通过在 onCreate() 中使用 setContentView() 设置您自己的视图布局来自定义屏幕布局。 To do this, your own view MUST contain a ListView object with the id "@android:id/list" (or list if it's in code)为此,您自己的视图必须包含一个 ID 为“@android:id/list”的 ListView 对象(或者如果它在代码中,则为列表)

so either use @+id/list and then R.id.list or extend your Activity with ListActivity Generally +id is used to create the new id in R while android:id is used in xml to customize with our own view as mentioned in the documentation.所以要么使用@+id/list 然后使用 R.id.list 或使用 ListActivity 扩展您的活动 通常 +id 用于在 R 中创建新 id 而 android:id 在 xml 中用于自定义我们自己的视图,如中所述文档。 Hence I am saying @android:id/list is specific to ListActivity and ListFragment.因此,我说 @android:id/list 特定于 ListActivity 和 ListFragment。

只需 jusr 从您的 MainActivity setContentView(R.layout.activity_main) 中删除一行;

暂无
暂无

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

相关问题 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 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