app is crashing when i am inserting background image

妖精的绣舞 提交于 2019-12-11 14:56:11

问题


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>

回答1:


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




回答2:


please put crashing text or you can replace this code

<?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"
    tools:context="com.android.spotsdialog.MainActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/rootLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/logo"
         />
</RelativeLayout >


来源:https://stackoverflow.com/questions/49462502/app-is-crashing-when-i-am-inserting-background-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!