Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resources$NotFoundException: If the resource you are trying to use is a vector resource, you may be referencing it in an unsupported way [duplicate]

I'm getting the following error message

android.content.res.Resources$NotFoundException: If the resource you are trying to use is a vector resource, you may be referencing it in an unsupported way. See AppCompatDelegate.setCompatVectorFromResourcesEnabled() for more info.

when im trying to set the following:

view.setBackgroundResource(R.drawable.highlight_background);

or

view.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.highlight_background));

I also tried using AppCompatImage. This happens on a device with Android 4.4.4. I've found another StackOverflow thread which provides to add

AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

into a MyApplication class and

    vectorDrawables.useSupportLibrary = true

into the build.gradle. But the error still occurs. The drawable consists of the following:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
   <stroke android:width="2dp" android:color="?attr/colorAccent" />
</shape>

It's just a line to encircle an image. Can anyone help me?

Thanks in advance!

like image 778
Lars Avatar asked Jul 17 '17 13:07

Lars


2 Answers

view.setBackgroundDrawable() is deprecated, use view.setBackgroundResource(int resId) instead

For example,

yourview.setBackgroundResource(R.drawable.highlight_background);

and offcourse change your color value like this

android:color="@color/color_defined_in_colors_xml_file"

Hope it will help.

like image 111
AndroidGeek Avatar answered Nov 15 '22 12:11

AndroidGeek


you can use imageView.setImageResource();

like image 36
Uday Ramjiyani Avatar answered Nov 15 '22 12:11

Uday Ramjiyani