资源$ NotFoundException在kitkat中的textView中将drawable设置为android:drawableLeft

时间:2017-08-24 06:47:58

标签: android android-drawable android-4.4-kitkat

我在棒棒糖前设备中收到错误。 drawable是矢量drawable,我在我的应用程序中使用了许多矢量drawables。那些已经在ImageView的src或背景上设置的矢量drawable,工作正常。但是使用textview设置drawableLeft会引发异常。这是stacktrace -

Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_place_black_24dp.xml from drawable resource ID #0x7f0200ee
                                                                              at android.content.res.Resources.loadDrawable(Resources.java:2152)
                                                                              at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
                                                                              at android.widget.TextView.<init>(TextView.java:840)
                                                                              at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:62)
                                                                              at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:58)
                                                                              at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
                                                                              at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1029)
                                                                              at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1087)
                                                                              at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
                                                                              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                              at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
                                                                              at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                              at com.overtatech.TotalTasty.MainActivity.onCreate(MainActivity.java:96) 
                                                                              at android.app.Activity.performCreate(Activity.java:5264) 
                                                                              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) 
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302) 
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
                                                                              at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 

1 个答案:

答案 0 :(得分:0)

创建可绘制文件ic_place_black_24dp.xml并粘贴到代码下方;

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">
<path
    android:fillColor="#FF000000"
    android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.87 -3.13,-7 -7,-7zM12,11.5c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5 2.5,1.12 2.5,2.5 -1.12,2.5 -2.5,2.5z"/>