2

I am new to Android dev and am working on my first app. I have been running into trouble trying to get an image view set up with my own image (stock photos on studio are working fine), and am getting the following error:

AAPT: error: '/home/joshua/AndroidStudioProjects/WSC/app/src/main/res/mipmap-xxxhdpi/wsc_foreground.png' is incompatible with attribute src (attr) reference|color.

I have researched around to even try to understand what this error is saying, and I think it is having trouble linking some file/resource?

I uploaded a .jpg using the add image asset option in android studio. I added a color background to the image, which was a hex number I selected.

I am not getting any errors or warnings until I build, at which point the build fails.

**Can someone please explain:

  1. What this error means.
  2. How to troubleshoot this.
  3. Where my mistake lies.**

I have attached the (hopefully sufficiently) relevant XML code.

Here is the image view inside of my fragment_first.xml, which is inside layout:

<ImageView
        android:id="@+id/wsc_image"
        android:layout_width="930dp"
        android:layout_height="585dp"
        android:layout_marginTop="44dp"
        android:contentDescription="@string/wsc_image_description"
        android:src="/home/joshua/AndroidStudioProjects/WSC/app/src/main/res/mipmap-xxxhdpi/wsc_foreground.png"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@+id/textview_first"
        app:layout_constraintStart_toStartOf="@+id/textview_first"
        app:layout_constraintTop_toBottomOf="@+id/textview_first"
        app:layout_constraintVertical_bias="0.0" />

I don't have an XML for the wsc_foreground.png, but do have a wsc.xml. I tried adding the full path in the wsc.xml for wsc_foreground.png, but this did not change anything.

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/wsc_background"/>
    <foreground android:drawable="/home/joshua/AndroidStudioProjects/WSC/app/src/main/res/mipmap-xxxhdpi/wsc_foreground.png"/>
</adaptive-icon>

My apologies if this is a dumb question and/or not clear. Please let me know in the comments if I need to clarify any of this.

Thanks!

5 Answers 5

5

I tried to add an image and got the same error... after an hour I realised that I had missed @ sign before drawable😥 and then I used "" instead of "/" in the naming!

Sign up to request clarification or add additional context in comments.

Comments

1

Joshua, Since it's been a while you likely have already figured this out, but the issue might be that you're using the absolute path.

instead of

/home/joshua/AndroidStudioProjects/WSC/app/src/main/res/mipmap-xxxhdpi/wsc_foreground.png

try (notice no file extension)

@mipmap/wsc_foreground

1 Comment

Thanks for the reply Scott. It has been a while, but what ended up working for me was deleting and re-adding the image into the project. I can't remember if I tried without a file extension or not. Thanks for the reply anyway, if it worked I would select best answer, but I have not way to verify this anymore sadly.
1

Just now i faced same kind of error and after 45 mins of debugging found out this is a very silly mistake.

android:background="E7E7E7" Error thrown: AAPT: error: E7E7E7 is incompatible with attribute src (attr) reference|color.

Answer: android:background="#E7E7E7"(i missed # symbol).

Joshua this might not be useful for you now as i was replying very late. This can be helpful for someone else in some other part of the world😜.

Comments

0
AAPT: error: is incompatible with attribute src (attr) reference|color

Today I face this error.

Now I solved this problem.

I saw webview id in the layout is red color. I think something happened. then I notice my webview id is wrong. I wrote android:id/"myWebView"

Then i wrote android:id="@+id/myWebView"

Then I run the app. It is working now.

Comments

0

First of all, copy any image from your laptop or pc and paste it to the drawable folder. rename it to a short name as example myprofile.jpg/png i don't know. change the src attribute in the ImageView to android:src="@drawable/myprofile" also you can set a background color, in my case i set the background color Black. then relaunch your device, it will be solved.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.