android.content.res.Resources $ NotFoundException:资源ID#0x7f040019

时间:2016-07-10 22:28:49

标签: java android

我不知道为什么我在行setContentView(R.layout.activity_main);中收到该异常。我试图清理这个项目,REBUILD,RERUN,REEVERYTHING ....但没有任何作用。

这是文件:

  

MainActivity.java

@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);
}
  

V21 / activity_main.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="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 个答案:

答案 0 :(得分:5)

您需要创建一个没有v21限定符的activity_main.xml文件,以便系统可以在较低的API模拟器上运行时默认返回该文件。

您的资源最终应该是:

Layout-qualifier

您可以详细了解限定符in this link