Java 资源不是可提取的
此代码在EmulatorAPI 18上导致强制关闭异常,并在ASUS Nexus 7API 21中工作Java 资源不是可提取的,java,android,android-layout,Java,Android,Android Layout,此代码在EmulatorAPI 18上导致强制关闭异常,并在ASUS Nexus 7API 21中工作 <View android:layout_width="400dp" android:layout_height="2dp" android:layout_marginTop="30dp" android:background="@color/light_gray" />
<View
android:layout_width="400dp"
android:layout_height="2dp"
android:layout_marginTop="30dp"
android:background="@color/light_gray" />
所以我在下面的代码中选择了drawable
<Button
android:layout_width="wrap_content"
android:layout_marginTop="30dp"
android:layout_height="wrap_content"
android:ems="10"
android:background="@drawable/login_btn_selector"
android:text="Login"
android:id="@+id/btnLogin" />
所以我尝试将登录名_btn_selected.xml放在res/drawable-hdpi-v4/文件夹中,然后它说res/drawable-hdpi/和res/drawable-hdpi-v4/之间出现重复文件,所以我将其从res/drawable-hdpi/中删除,然后再次在v4文件夹中发现相同的资源未发现异常
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi-v4/login_btn_selected.xml from drawable resource ID #0x7f020095
所以最后我来了
问题是,
我想知道这个问题是在模拟器上还是在真实设备上
如果在真实设备中也意味着我如何克服这一点
我想使用@color/light\u gray而不是硬编码,我还想使用可绘制选择器
注意:我已经删除并重新创建了模拟器,没有用。我也在API19模拟器上测试过,同样的问题
任何解决方案都是非常值得欣赏的。我认为最好的方法是,首先在drawable文件夹中创建一个xml文件,然后执行以下操作
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/light_gray" />
</shape>
<View
android:layout_width="400dp"
android:layout_height="2dp"
android:layout_marginTop="30dp"
android:background="@ drawable/light_gray" />
e、 g.light_gray.xml然后执行如下操作
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/light_gray" />
</shape>
<View
android:layout_width="400dp"
android:layout_height="2dp"
android:layout_marginTop="30dp"
android:background="@ drawable/light_gray" />
一旦你保存了它
更改您的代码如下
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/light_gray" />
</shape>
<View
android:layout_width="400dp"
android:layout_height="2dp"
android:layout_marginTop="30dp"
android:background="@ drawable/light_gray" />
但请确保将文件light_gray.xml仅放在drawable文件夹中。不要将同一个文件放在drawable hdpi或drawable-hdpi-v4中,以此类推我认为最好的方法是,首先在drawable文件夹中创建一个xml文件,然后执行以下操作
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/light_gray" />
</shape>
<View
android:layout_width="400dp"
android:layout_height="2dp"
android:layout_marginTop="30dp"
android:background="@ drawable/light_gray" />
e、 g.light_gray.xml然后执行如下操作
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/light_gray" />
</shape>
<View
android:layout_width="400dp"
android:layout_height="2dp"
android:layout_marginTop="30dp"
android:background="@ drawable/light_gray" />
一旦你保存了它
更改您的代码如下
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/light_gray" />
</shape>
<View
android:layout_width="400dp"
android:layout_height="2dp"
android:layout_marginTop="30dp"
android:background="@ drawable/light_gray" />
但请确保将文件light_gray.xml仅放在drawable文件夹中。不要将同一个文件放入drawable hdpi或drawable-hdpi-v4等您的颜色资源必须位于Android资源文件中,即:在colors.xml文件中。 Android不会抱怨你在哪里设置它,但它必须被定义为一个颜色资源 即: 然后你说:所以我试着把登录名放在selected.xml上 这似乎是导致死亡的原因
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi-v4/login_btn_selected.xml from drawable resource ID #0x7f020095.
您的颜色资源必须位于Android资源文件中,即:colors.xml文件中。 Android不会抱怨你在哪里设置它,但它必须被定义为一个颜色资源 即: 然后你说:所以我试着把登录名放在selected.xml上 这似乎是导致死亡的原因
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi-v4/login_btn_selected.xml from drawable resource ID #0x7f020095.
这是因为我的颜色资源文件位于\res\values-21文件夹下,现在将其移动到\res\values\folder,现在应用程序工作正常。谢谢朋友。这是因为我的颜色资源文件位于\res\values-21文件夹下,现在将其移动到\res\values\folder,现在应用程序工作正常。谢谢您的朋友。另外,请确保您没有将imageView的背景设置为selectableItemBackgroundBorderless,否则较旧的设备将出现以下错误:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:selectableItemBackgroundBorderless" />
另外,请确保没有将imageView的背景设置为selectableItemBackgroundBorderless,否则旧设备将出现以下错误:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:selectableItemBackgroundBorderless" />
在我最近开发的应用程序中,我也遇到了同样的问题。在我的例子中,问题是我在名为drawable-v21的文件夹中放置了一个图像,这在旧的android API中是不可用的
解决方法是将您的drawable也放在drawable-…dpi文件夹中。我在最近制作的应用程序中遇到了同样的问题。在我的例子中,问题是我在名为drawable-v21的文件夹中放置了一个图像,这在旧的android API中是不可用的
解决方案是将您的drawable也放在drawable-…dpi文件夹中。像这样,只有我定义了bro。。它在nexus 7中工作得非常完美。像这样,只有我定义了兄弟。。它在Nexus7中工作得很好。这是否回答了您的问题@我已经更新了我的答案。这能回答你的问题吗@我已经更新了我的答案。