0

Everytime I put a @drawable item it appears underlined in red. It worked before but I pressed one of the options in the light bulb that appears next to the line and then all drawables became errors. I can't find the problem... I'm working with Android Studio. I tried to rebuild, clean, reimport... and nothing solves the problem.

My code:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:shrinkColumns="*"  android:stretchColumns="*" android:background="#ffffff">


    <TableRow
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:gravity="center_horizontal">

        <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter"
        android:id="@+id/back"
        android:layout_marginTop="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginLeft="20dp"
        android:background="@null"
        android:src="@drawable/backstate" /> /////////////////ERROR in "@drawable/backstate" (Underlined in red)

    </TableRow>

    <TableRow
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:gravity="center_horizontal">

        <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter"
        android:id="@+id/blanc"
        android:layout_marginTop="50dp"
        android:layout_marginLeft="20dp"
        android:background="@null"
        android:src="@drawable/blancstate"/> /////////////////SAME ERROR 

        <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter"
        android:id="@+id/groc"
        android:layout_marginTop="50dp"
        android:layout_marginRight="20dp"
        android:background="@null"
        android:src="@drawable/grocstate"/> /////////////////SAME ERROR

    </TableRow>

    <TableRow
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:gravity="center_horizontal">

        <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter"
        android:id="@+id/taronja"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        android:background="@null"
        android:src="@drawable/taronjastate"/> /////////////////SAME ERROR

        <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter"
        android:id="@+id/vermell"
        android:layout_marginTop="20dp"
        android:layout_marginRight="20dp"
        android:background="@null"
        android:src="@drawable/vermellstate"/> /////////////////SAME ERROR

    </TableRow>
</TableLayout>

All xml states are correct, layouts are well formed, i didn't change anything from the code, and by clicking that option that I didn't remember, all drawables started to give me errors.

ERROR DESCRIPTION: Top level element is not completed. Valid XML document must have a root tag.

Anyway the document is well formed... And it says the same error each time I write "@drawable/..."

EDIT: I found the origin of the problem. android namespace is the problem, if I change it for tools namespace it works. tools:src="@drawable/vermellstate" for example.

Can anyone help me please?

9
  • Does Image Exists ??
    – Maveňツ
    Commented Oct 6, 2014 at 7:40
  • Yes of course, Images are in a folder called drawable-sw480dp and layouts in a folder named layout-sw480dp. States and images are in the same folder. And it was working until I press that option... The way is that I start another project from 0 and I copy the code of the old one, the problem persists.
    – Llangostu
    Commented Oct 6, 2014 at 7:46
  • Are you getting this message on mouse click error: Error: No resource found that matches the given name (at 'src' with value '@drawable/backstate'). ?
    – Maveňツ
    Commented Oct 6, 2014 at 7:48
  • Yes at first, now it doesn't appear more. But maybe still happens.
    – Llangostu
    Commented Oct 6, 2014 at 7:52
  • Does the app still work and display correctly despite this or does it actually give you an exception when you run it?
    – Chris
    Commented Oct 6, 2014 at 7:59

2 Answers 2

4

Try this:

Select item that is displaying error, then press alt + enter on the drawable item which calls error (for example:"@drawable/vermellstate") and select "Uninject language/reference"

1

Could be the case that you injected language by mistake. If you are using Android Studio right click the code in question then->Local History->Show History and revert to a time prior to "Language Injection Configuration Update" .

Hope it helped, Best of luck !

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.