Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error:error: 'drawable/delete.png' is incompatible with attribute android:background (attr) reference|color

I'm having this problem when I try to change my android:background in my activity's XML file.

Information:Gradle tasks [:app:assembleDebug]
C:\Users\Valentin\AndroidStudioProjects\CedarRestaurants4\CedarRestaurants3\app\src\main\res\layout\activity_dynamic_view_ordering.xml
Error:error: 'drawable/delete' is incompatible with attribute android:background (attr) reference|color.
Error:'drawable/delete' is incompatible with attribute android:background (attr) reference|color.
Error:failed linking file resources.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt
Information:BUILD FAILED in 4s
Information:7 errors
Information:0 warnings
Information:See complete output in console

My Activity's XML file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/parent_linear_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="5dp"
    android:orientation="vertical" >
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal" >
        <EditText
            android:id="@+id/number_edit_text"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="5" />

        <Button
            android:id="@+id/delete_button"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="drawable/delete.png"
            android:onClick="onDelete" />
    </LinearLayout>
    <Button
        android:id="@+id/add_field_button"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:background="#555"
        android:layout_gravity="center"
        android:onClick="onAddField"
        android:textColor="#FFF"
        android:text="New"
        android:paddingLeft="5dp"/>
</LinearLayout>

<Button
    android:id="@+id/placeOrderButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/parent_linear_layout"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="250sp"
    android:text="@string/place_order"
    android:textSize="32sp" />


</RelativeLayout>

I copied the activity layout file and activity from a tutorial project and am trying to change the image assets to something more modern-looking.

I've already made sure my delete.png is inside /src/main/res/drawable and already tried getting rid of the .png at the end, but with no luck. Any help is appreciated.

like image 980
defkey123 Avatar asked Feb 26 '19 07:02

defkey123


Video Answer


1 Answers

You forgot to add @ to your drawable and remove extention. So change your

android:background="drawable/delete.png"

to this

android:src="@drawable/delete"
like image 154
Tejas Pandya Avatar answered Sep 27 '22 19:09

Tejas Pandya