I am using vector in ImageView in my activity, the app works just fine on android 7.0 but crashes on android 4.4. Logcat says, Resources$NotFoundException
. I have tried solutions posted here on stackoverflow but none of them seems to be working.
These are the solutions I tried.
added this in my gradle file
defaultConfig { vectorDrawables.useSupportLibrary = true }
Added this in OnCreate of activity
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
- Replaced
android:src
withapp:srcCompat
in XML file.
This is my code in XML
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_arrow_back_white_24dp"
android:tint="@color/colorPrimary"
android:id="@+id/details_back"
android:layout_margin="15dp"
android:layout_alignParentStart="true"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/share"
android:tint="@color/colorPrimary"
android:id="@+id/details_share"
android:layout_margin="15dp"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
this is the code in JAVA file
ImageView detail_share;
detail_share = (ImageView) findViewById(R.id.details_share);
detail_share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// code for sharing item
}
});
Also, the error occurs in second ImageView, not the first one, despite of being exactly same. I am treating both images exactly same in java file too.