android.content.res.Resources $ NotFoundExceptionexception:来自drawable资源ID的文件res / drawable / my.xml

这个xml有什么问题,我试图按下按钮的感觉。 我得到一个例外,我无法理解。 ResourceNotFound

在我的layout.xml中

 

我在drawable文件夹中的submitbuttonpress.xml

      

exception(logcat)

 07-17 19:07:25.072: E/AndroidRuntime(2225): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.taxeeta/com.itaxeeta.BookingExperience}: android.view.InflateException: Binary XML file line #326: Error inflating class android.widget.Button 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.os.Handler.dispatchMessage(Handler.java:99) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.os.Looper.loop(Looper.java:130) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.app.ActivityThread.main(ActivityThread.java:3687) 07-17 19:07:25.072: E/AndroidRuntime(2225): at java.lang.reflect.Method.invokeNative(Native Method) 07-17 19:07:25.072: E/AndroidRuntime(2225): at java.lang.reflect.Method.invoke(Method.java:507) 07-17 19:07:25.072: E/AndroidRuntime(2225): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 07-17 19:07:25.072: E/AndroidRuntime(2225): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625) 07-17 19:07:25.072: E/AndroidRuntime(2225): at dalvik.system.NativeStart.main(Native Method) 07-17 19:07:25.072: E/AndroidRuntime(2225): Caused by: android.view.InflateException: Binary XML file line #326: Error inflating class android.widget.Button 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.view.LayoutInflater.createView(LayoutInflater.java:518) 07-17 19:07:25.072: E/AndroidRuntime(2225): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.view.LayoutInflater.inflate(LayoutInflater.java:408) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 07-17 19:07:25.072: E/AndroidRuntime(2225): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:216) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.app.Activity.setContentView(Activity.java:1660) 07-17 19:07:25.072: E/AndroidRuntime(2225): at com.itaxeeta.BookingExperience.onCreate(BookingExperience.java:100) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615) 07-17 19:07:25.072: E/AndroidRuntime(2225): ... 11 more 07-17 19:07:25.072: E/AndroidRuntime(2225): Caused by: java.lang.reflect.InvocationTargetException 07-17 19:07:25.072: E/AndroidRuntime(2225): at java.lang.reflect.Constructor.constructNative(Native Method) 07-17 19:07:25.072: E/AndroidRuntime(2225): at java.lang.reflect.Constructor.newInstance(Constructor.java:415) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.view.LayoutInflater.createView(LayoutInflater.java:505) 07-17 19:07:25.072: E/AndroidRuntime(2225): ... 27 more 07-17 19:07:25.072: E/AndroidRuntime(2225): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/nextprevbuttonpress.xml from drawable resource ID #0x7f02003e 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.content.res.Resources.loadDrawable(Resources.java:1697) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.content.res.TypedArray.getDrawable(TypedArray.java:601) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.view.View.(View.java:1951) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.widget.TextView.(TextView.java:389) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.widget.Button.(Button.java:108) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.widget.Button.(Button.java:104) 07-17 19:07:25.072: E/AndroidRuntime(2225): ... 30 more 07-17 19:07:25.072: E/AndroidRuntime(2225): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #3:  tag requires a 'drawable' attribute or child tag defining a drawable 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:167) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728) 07-17 19:07:25.072: E/AndroidRuntime(2225): at android.content.res.Resources.loadDrawable(Resources.java:1694) 07-17 19:07:25.072: E/AndroidRuntime(2225): ... 35 more 

一旦试试这个

在选择器状态下,需要添加drawable,在您的情况下,您希望在选择器状态中添加颜色。因此,可以使用资源中的颜色创建可绘制的颜色。 它将作为ColorDrawable工作

请检查以下代码

     

values / string.xml表示颜色

  #AAAAAA #777777 

android:background属性不存在。 执行此操作的正确方法是首先使用以下内容创建新的资源文件res/colors.xml

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

然后只需将selector更改为以下内容:

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

这会自动创建一个ColorDrawable并将其指定为该状态的drawable。