当前位置: 首页 > 知识库问答 >
问题:

Android.content.res.resources$NotFoundException:资源ID#0x7F040019

司寇望
2023-03-14
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    recyclerView1 = (RecyclerView) findViewById(R.id.recycleView1);
    adapter1 = new MyCustomAdapter(this, Group.getData());
    recyclerView1.setAdapter(adapter1);
    GridLayoutManager mGridLayoutManager = new GridLayoutManager(this, 5); // (Context context, int spanCount)
    recyclerView1.setLayoutManager(mGridLayoutManager);

    recyclerView = (RecyclerView) findViewById(R.id.recycleView);
    adapter = new MyCustomAdapter(this, Data.getData());
    recyclerView.setAdapter(adapter);
    LinearLayoutManager mLinearLayoutManagerHorizontal = new LinearLayoutManager(this); // (Context context)
    mLinearLayoutManagerHorizontal.setOrientation(LinearLayoutManager.HORIZONTAL);
    recyclerView.setLayoutManager(mLinearLayoutManagerHorizontal);
    adapter.setAddapter(adapter1);
    adapter1.setAddapter(adapter);
   final RecyclerViewFastScroller fastScroller = (RecyclerViewFastScroller) findViewById(R.id.fastscroller);
    fastScroller.setRecyclerView(recyclerView);
   fastScroller.setViewsToUse(R.layout.recycler_view_fast_scroller__fast_scroller, R.id.fastscroller_bubble, R.id.fastscroller_handle);



}
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return super.onCreateOptionsMenu(menu);
}
<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="com.group.tarekit.swapgroup.MainActivity"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycleView"
        android:layout_width="match_parent"
        android:layout_height="130dp">
    </android.support.v7.widget.RecyclerView>

    <com.group.tarekit.swapgroup.RecyclerViewFastScroller
        android:id="@+id/fastscroller"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/darker_gray"
        android:id="@+id/view" />

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Group Mates"
            android:id="@+id/textView"
            android:layout_gravity="center_horizontal"
            android:textSize="22dp"
            android:textColor="#2cb21a" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycleView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </android.support.v7.widget.RecyclerView>
    </LinearLayout>

</LinearLayout>

Android显示器

07-11 00:22:20.750 21017-21017/com.group.tarekit.swapgroup E/AndroidRuntime: FATAL EXCEPTION: main
     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.group.tarekit.swapgroup/com.group.tarekit.swapgroup.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f040019
         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2114)
         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
         at android.app.ActivityThread.access$700(ActivityThread.java:143)
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
         at android.os.Handler.dispatchMessage(Handler.java:99)
         at android.os.Looper.loop(Looper.java:137)
         at android.app.ActivityThread.main(ActivityThread.java:4963)
         at java.lang.reflect.Method.invokeNative(Native Method)
         at java.lang.reflect.Method.invoke(Method.java:511)
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
         at dalvik.system.NativeStart.main(Native Method)
      Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f040019
         at android.content.res.Resources.getValue(Resources.java:1339)
         at android.content.res.Resources.loadXmlResourceParser(Resources.java:2445)
         at android.content.res.Resources.getLayout(Resources.java:1178)
         at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
         at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
         at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
         at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
         at com.group.tarekit.swapgroup.MainActivity.onCreate(MainActivity.java:23)
         at android.app.Activity.performCreate(Activity.java:5184)
         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2078)
         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139) 
         at android.app.ActivityThread.access$700(ActivityThread.java:143) 
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241) 
         at android.os.Handler.dispatchMessage(Handler.java:99) 
         at android.os.Looper.loop(Looper.java:137) 
         at android.app.ActivityThread.main(ActivityThread.java:4963) 
         at java.lang.reflect.Method.invokeNative(Native Method) 
         at java.lang.reflect.Method.invoke(Method.java:511) 
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038) 
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) 
         at dalvik.system.NativeStart.main(Native Method) 

共有1个答案

岳正阳
2023-03-14

您需要创建一个activity_main.xml文件,而不使用v21限定符,这样系统在运行较低API模拟器时就可以默认返回该文件。

您的资源最终应该是这样的:

您可以在此链接中了解有关限定符的更多信息。

 类似资料: