编程语言
首页 > 编程语言> > java-找不到某些可绘制对象

java-找不到某些可绘制对象

作者:互联网

在添加了更多矢量可绘制对象之后,我注意到前面的一些不可用(大约11个).与其余的我没有任何问题-它们显示正确.我用诸如image.setImageResource(R.drawable.path_to_image);之类的方法将Java类中的每个drawable链接起来;并且大多数链接都没有任何问题.我只有几个这样的问题.
在运行应用程序并尝试显示这些可绘制对象之后,出现了这样的错误:

Unable to find resource: 2131099763
android.content.res.Resources$NotFoundException: Drawable com.example.example_app:drawable/f_user_achievements_learning1h with resource ID #0x7f060073
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/f_user_achievements_learning1h.xml from drawable resource ID #0x7f060073
    at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:725)
    at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)
    at android.content.res.Resources.getDrawable(Resources.java:767)
    at android.content.Context.getDrawable(Context.java:525)
    at android.widget.ImageView.resolveUri(ImageView.java:840)
    at android.widget.ImageView.onMeasure(ImageView.java:982)
    at android.view.View.measure(View.java:19734)
    at android.widget.TableRow.measureChildBeforeLayout(TableRow.java:222)
    at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1117)
    at android.widget.TableRow.onMeasure(TableRow.java:113)
    at android.view.View.measure(View.java:19734)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
    at android.widget.LinearLayout.forceUniformWidth(LinearLayout.java:1000)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:980)
    at android.widget.TableLayout.measureVertical(TableLayout.java:473)
    at android.widget.TableLayout.onMeasure(TableLayout.java:436)
    at android.view.View.measure(View.java:19734)
    at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1293)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.widget.ScrollView.onMeasure(ScrollView.java:340)
    at android.view.View.measure(View.java:19734)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:911)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
    at android.view.View.measure(View.java:19734)
    at android.widget.RelativeLayout.measureChild(RelativeLayout.java:676)
    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:479)
    at android.view.View.measure(View.java:19734)
    at android.widget.RelativeLayout.measureChild(RelativeLayout.java:676)
    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:479)
    at android.view.View.measure(View.java:19734)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
    at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:671)
    at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:90)
    at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1319)
    at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:736)
    at android.view.View.measure(View.java:19734)
    at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1081)
    at android.view.View.measure(View.java:19734)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
    at android.view.View.measure(View.java:19734)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
    at android.view.View.measure(View.java:19734)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.view.View.measure(View.java:19734)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
    at android.view.View.measure(View.java:19734)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at com.android.internal.policy.DecorView.onMeasure(DecorView.java:687)
    at android.view.View.measure(View.java:19734)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2271)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1358)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1607)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1246)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6301)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
    at android.view.Choreographer.doCallbacks(Choreographer.java:683)
    at android.view.Choreographer.doFrame(Choreographer.java:619)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6077)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
 Caused by: java.lang.IllegalArgumentException: Path string cannot be empty.
    at android.util.PathParser.nCreatePathDataFromString(Native Method)
    at android.util.PathParser.-wrap1(PathParser.java)
    at android.util.PathParser$PathData.<init>(PathParser.java:74)
    at android.graphics.drawable.VectorDrawable$VFullPath.updateStateFromTypedArray(VectorDrawable.java:1556)
    at android.graphics.drawable.VectorDrawable$VFullPath.inflate(VectorDrawable.java:1507)
    at android.graphics.drawable.VectorDrawable.inflateChildElements(VectorDrawable.java:693)
    at android.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:598)
    at android.graphics.drawable.DrawableInflater.inflateFromXml(DrawableInflater.java:130)
    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1227)
    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1200)
    at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:715)
        ... 74 more

这是Java类的片段,我在其中链接了drawable:

@Override
    protected void setChoiceState() {
        if(achievement.isAchieved()) {
            image.setAlpha(ITEM_CHOSEN);
            image.setImageResource(achievement.getResId());
        } else {
            image.setAlpha(ITEM_NOT_CHOSEN);
            image.setImageResource(R.drawable.f_user_achievements_not_achieved);
        }
    }

Achievement.getResId()是可绘制路径.我也尝试过将其更改为R.drawable.path_to_drawable之类的原始路径,但它也无法正常工作.但是,以下行:image.setImageResource(R.drawable.f_user_achievements_not_achieved);工作正常.

这是我的.gradle文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.1.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '27.0.2'

    defaultConfig {
        applicationId "com.example.example_app"
        vectorDrawables.useSupportLibrary = true
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
    }

    dexOptions {
        jumboMode true
        javaMaxHeapSize "2g"
    }
}

repositories {
    maven {
        url "https://maven.google.com"
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/gson-2.8.0.jar')
    compile files('libs/commons-lang-2.3.jar')
    compile files('libs/httpclient-4.5.3.jar')
    compile 'org.apache.httpcomponents:httpcore:4.4.1'
    compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.android.support:design:24.1.1'
    compile 'com.android.support:support-v4:24.1.1'
    compile 'com.google.android.gms:play-services-ads:11.6.2'
    compile 'com.google.android.gms:play-services-auth:11.6.2'
    compile 'com.android.support:multidex:1.0.0'
    testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'

如果您需要任何其他文件,只需发表评论,我会附上它们

编辑

我添加了两个额外的可绘制对象(均为Vector Assets)-一个没有使用,而另一个没有问题.第一个不工作,但是第二个工作正常,那么仅表示矢量可绘制的xml文件会出现问题吗?

这是一个不起作用的矢量可绘制对象的xml文件:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.000002"
        android:viewportHeight="24.000002">
    <path
        android:pathData="M12,12m-11.803,0a11.803,11.803 0,1 1,23.605 0a11.803,11.803 0,1 1,-23.605 0"
        android:strokeLineCap="round"
        android:fillAlpha="1"
        android:strokeColor="#ffffff"
        android:fillColor="#1b1b1b"
        android:strokeWidth="0.40124387"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="m8.02,15.376 l0,-1.975c0,-0.821 1.742,-1.929 1.742,-1.929l0,-0.662c0,0 -1.742,-1.031 -1.742,-1.852l0,-1.975"
        android:strokeLineCap="round"
        android:strokeColor="#ffffff"
        android:fillColor="#00000000"
        android:strokeWidth="1.03580773"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="m12.623,15.376 l0,-1.975c0,-0.821 -1.742,-1.929 -1.742,-1.929l0,-0.662c0,0 1.742,-1.031 1.742,-1.852l0,-1.975"
        android:strokeLineCap="round"
        android:strokeColor="#ffffff"
        android:fillColor="#00000000"
        android:strokeWidth="1.03580773"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="M7.18,5.604L13.463,5.604A0.295,0.295 117.507,0 1,13.759 5.9L13.759,6.087A0.295,0.295 0,0 1,13.463 6.382L7.18,6.382A0.295,0.295 0,0 1,6.885 6.087L6.885,5.9A0.295,0.295 117.507,0 1,7.18 5.604z"
        android:strokeLineCap="round"
        android:fillAlpha="1"
        android:strokeColor="#00000000"
        android:fillColor="#ffffff"
        android:strokeWidth="0.39954987"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="M7.18,15.977L13.463,15.977A0.295,0.295 0,0 1,13.759 16.273L13.759,16.459A0.295,0.295 0,0 1,13.463 16.755L7.18,16.755A0.295,0.295 0,0 1,6.885 16.459L6.885,16.273A0.295,0.295 0,0 1,7.18 15.977z"
        android:strokeLineCap="round"
        android:fillAlpha="1"
        android:strokeColor="#00000000"
        android:fillColor="#ffffff"
        android:strokeWidth="0.39954987"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="m8.853,15.506 l2.937,0 -1.43,-0.988z"
        android:strokeLineCap="round"
        android:fillAlpha="1"
        android:strokeColor="#ffb3cc"
        android:fillColor="#ffb3cc"
        android:strokeWidth="0.43446419"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="m8.909,8.698 l2.804,0c0.314,0.066 -0.754,1.004 -1.399,1.366C9.655,9.709 8.665,8.784 8.909,8.698Z"
        android:strokeLineCap="round"
        android:fillAlpha="1"
        android:strokeColor="#ffb3cc"
        android:fillColor="#ffb3cc"
        android:strokeWidth="0.40527168"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="m-21.276,14.911c0.008,0.022 0.418,1.042 0.911,2.265 0.49,1.223 0.9,2.24 0.905,2.256 0.019,0.049 0.873,0.049 0.892,0.003 0.006,-0.019 0.416,-1.037 0.905,-2.259 0.492,-1.223 0.903,-2.243 0.911,-2.265 0.014,-0.033 -0.046,-0.038 -0.418,-0.033l-0.432,0.008 -0.7,1.701c-0.383,0.935 -0.703,1.701 -0.711,1.701 -0.008,0 -0.328,-0.766 -0.711,-1.701l-0.7,-1.701 -0.432,-0.008c-0.372,-0.006 -0.432,0 -0.418,0.033z"
        android:fillAlpha="1"
        android:strokeColor="#00000000"
        android:fillColor="#ffffff"/>
    <path
        android:pathData=""
        android:strokeLineCap="round"
        android:fillAlpha="1"
        android:strokeColor="#00000000"
        android:fillColor="#ffb3cc"
        android:strokeWidth="0.84933162"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="M17.063,16.438m-2.344,0a2.344,2.344 0,1 1,4.689 0a2.344,2.344 0,1 1,-4.689 0"
        android:strokeLineCap="round"
        android:fillAlpha="1"
        android:strokeColor="#ffffff"
        android:fillColor="#00000000"
        android:strokeWidth="0.43581513"
        android:strokeLineJoin="round"
        android:strokeAlpha="1"/>
    <path
        android:pathData="m16.973,16.438 l0,1.101 0.16,0 0.161,0 0.004,-0.492 0.004,-0.491 0.036,-0.078c0.072,-0.156 0.209,-0.238 0.395,-0.238 0.122,0 0.207,0.033 0.266,0.106 0.08,0.098 0.082,0.105 0.087,0.676l0.004,0.517 0.167,0 0.166,0 0,-0.525c0,-0.58 -0.006,-0.653 -0.073,-0.783 -0.181,-0.36 -0.752,-0.396 -0.997,-0.064l-0.056,0.075 0,-0.453 0,-0.453 -0.161,0 -0.161,0 0,1.101z"
        android:fillAlpha="1"
        android:strokeColor="#00000000"
        android:fillColor="#ffb3cc"/>
    <path
        android:pathData="m15.704,15.553 l0,0.155 0.21,0 0.21,0 0,0.885 0,0.885 0.167,0 0.167,0 0,-1.039 0,-1.039 -0.377,0 -0.377,0 0,0.155z"
        android:fillAlpha="1"
        android:strokeColor="#00000000"
        android:fillColor="#ffb3cc"/>
</vector>

解决方法:

文件中间一行带有空路径数据.也许是罪魁祸首(肯定看起来不正确):

<path
    android:pathData=""
    android:strokeLineCap="round"
    android:fillAlpha="1"
    android:strokeColor="#00000000"
    android:fillColor="#ffb3cc"
    android:strokeWidth="0.84933162"
    android:strokeLineJoin="round"
    android:strokeAlpha="1"/>

标签:android-drawable,java,android
来源: https://codeday.me/bug/20191025/1929011.html