2014-03-03 45 views
4

我有在那里我得到这个错误的问题...资源未发现异常的selector.xml

03-02 19:59:03.539:E/AndroidRuntime(11177): 的Java。 lang.RuntimeException:无法启动活动 ComponentInfo {com.comp4020.kitchenaid/com.kitchenaid.MainActivity}: android.content.res.Resources $ NotFoundException:文件 来自可绘制资源ID的res/drawable/main_button.xml#0x7f020003

我不知道为什么会发生这种情况。该资源绝对存在,它的命名正确无误。我能想到的唯一想法是我在程序中添加了字符,但没有默认字符集,所以它询问“更改为UTF-8”,我说是的。

我如下分配这个资源......

ingButton.setBackgroundResource(R.drawable.main_button); 
nextButton.setBackgroundResource(R.drawable.main_button); 
prevButton.setBackgroundResource(R.drawable.main_button); 
timerButton.setBackgroundResource(R.drawable.main_button); 

我也尝试清洗工程。我不知道发生了什么。

编辑:这里是绘制

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item 
     android:state_pressed="true" 
     android:background="@drawable/gradient_pressed" 
     /> 
    <item android:background="@drawable/gradient"/> 

</selector> 

gradient.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" > 
    <gradient android:startColor="@color/gradientDark" 
       android:centerColor="@color/gradientDark" 
       android:endColor="@color/gradientLight" 
       android:angle="90" /> 
</shape> 

gradient_pressed.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" > 
    <gradient android:startColor="@color/highlightGradientDark" 
       android:centerColor="@color/highlightGradientDark" 
       android:endColor="@color/highlightGradientLight" 
       android:angle="90" /> 

</shape> 
+0

您是否尝试过清洁和重建项目? – codeMagic

+0

你能否确认并发布你的main_button.xml文件 – Prakash

+0

只是想检查一下这些drawable可能是不同的尺寸,其中有些不在那里?即:你正在加载一些平板电脑的东西? – reidisaki

回答

-1

的Android新版本的解释更多的细节一点点:

E/AndroidRuntime(5591): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML 
file line #4: <item> tag requires a 'drawable' attribute or child tag defining a drawable 

的问题是,选择具有安卓颜色或在您的情况的android:背景中的每个项目,而不是机器人:可绘制,更改为前者解决了这个问题。

+0

你是什么意思改变为前者?前者是什么?非常模糊的解释。 – ulusoyca

+0

@ulusoyca对不起,你的英文不好,前者是指“后者”,在句子中,意思是将android:background改为android:drawable应该可以解决问题 – htafoya