Search code examples
androidandroid-relativelayout

app is crashing when i am inserting background image


my app is crashing when I am inserting an image and I am not getting log report too when I am writing android:background="@drawable/logo" my app is crashing

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/rootLayout"
    android:background="@drawable/logo"
    tools:context="com.android.spotsdialog.MainActivity">   
</RelativeLayout>

Solution

  • The problem is you probably testing on lower API version then API24. So it will throw ResourceNotFoundException cause drawable does not exists for it .

    So You have to have a copy of it normal drawable folder drawable . Or in all drawable-v24, drawable-v21 and drawable . put the drawable in all folder most importantly in drawable.

    drawable
    drawable-v21
    drawable-v24