在 setContentView 上找不到资源异常

Posted

技术标签:

【中文标题】在 setContentView 上找不到资源异常【英文标题】:Resource Not found exception on setContentView 【发布时间】:2016-06-24 23:21:38 【问题描述】:

美好的一天。首先我要说的是,谷歌没有找到任何方法帮助我,所以我来到这里!令人沮丧的问题,但这是正在发生的事情。我有简单的布局文件夹和简单的布局文件。该应用程序在几个屏幕上运行良好,并且在 HomeActivity 屏幕上它正在崩溃给出这个问题。重要的是要提到我已经在 2 个不同的设备上对其进行了测试。在第一个设备上它一切正常,在第二个设备上它不是。两个设备都处于纵向模式并且都具有相同的屏幕尺寸。我不知道 android studio 要求我做什么,但该应用程序运行良好,我没有做任何事情,突然 android studio 决定给我这个例外。所以这是我的实际视图崩溃的代码。

xml 文件

<?xml version="1.0" encoding="utf-8"?>

<include
    layout="@layout/app_bar_home"
    android:layout_
    android:layout_ />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_
    android:layout_
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_home"
    app:menu="@menu/activity_home_drawer" />

&lt;include&gt;的xml文件

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.AppBarLayout
    android:layout_
    android:layout_
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_
        android:layout_
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_home" />


<android.support.design.widget.FloatingActionMenu
    android:id="@+id/fab"
    android:layout_
    android:layout_
    android:layout_gravity="bottom|right"
    android:layout_marginBottom="8dp"
    android:layout_marginRight="8dp"
    android:src="@drawable/fab_add"
    app:layout_behavior="ink.utils.ScrollAwareFABBehavior"
    fab:menu_colorNormal="@color/colorPrimary"
    fab:menu_colorPressed="@color/colorPrimaryDark"
    fab:menu_colorRipple="#cccccc">

    <fab.FloatingActionButton
        android:id="@+id/messages"
        android:layout_
        android:layout_
        android:src="@drawable/ic_message_white_24dp"
        fab:fab_colorNormal="#444f65"
        fab:fab_colorPressed="#636e85"
        fab:fab_label="@string/messageText"
        fab:fab_size="mini" />

    <fab.FloatingActionButton
        android:id="@+id/makePost"
        android:layout_
        android:layout_
        android:src="@drawable/ic_create_white_24dp"
        fab:fab_colorNormal="#444f65"
        fab:fab_colorPressed="#636e85"
        fab:fab_label="@string/makePostString"
        fab:fab_size="mini" />
</android.support.design.widget.FloatingActionMenu>

setContentView 我遇到实际崩溃的活动

public class HomeActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener, View.OnClickListener 

private FloatingActionMenu mFab;
private ImageView mProfileImage;
private SharedHelper mSharedHelper;
private FloatingActionButton mMessages;
private FloatingActionButton mNewPost;
private Feed mFeed;
private MyFriends mMyFriends;
private Toolbar mToolbar;
private DrawerLayout mDrawer;
public static String PROFILE;
public static String FEED;
public static String MESSAGES;
public static String GROUPS;
public static String FRIENDS;
public static String SETTINGS;

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

除了谷歌搜索和尝试所有可能的解决方案检查我肯定没有的布局额外文件夹之外,我只有一个布局文件夹,我尝试过清理项目、重建、使缓存无效和重新启动,但没有任何帮助。 . 这是xml文件的gradle依赖

 compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'

没什么特别的,请你帮我告诉我该怎么办?

【问题讨论】:

ResourceNotFound on layout inflation的可能重复 【参考方案1】:

还有一个'include' -layout content_home

【讨论】:

【参考方案2】:

得到了修复,这对于某人来说是非常奇怪的。无论如何,我找到了该项目的可绘制文件。当我用键 name 重构一个变量时,问题就出现了,我不知道为什么 android studio 决定重命名我所有的项目 keys within name to my input one.So there were no compiler issues nothing at all (which is far weird even) and all was working fine on one phone,and not on the other.So i removed that issue renamed to the default 'name' key and all got working.Be carefull as there are lots 现在都是奇怪的东西。

【讨论】:

以上是关于在 setContentView 上找不到资源异常的主要内容,如果未能解决你的问题,请参考以下文章

在 Doctrine2 上找不到实体异常

类在firebase消息颤动上找不到异常

在共享主机中的 Lumen 项目上找不到类异常

在 Heroku 上找不到资源“语料库/wordnet”

未处理的异常:MissingPluginException(在通道 plugins.flutter.io/firebase_messaging 上找不到方法 getToken 的实现)

Laravel 8“在此服务器上找不到请求的资源 /dashboard。”