Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Cannot Resolve Symbol" Error when using android:id="@+android:id/my_id"

When I am adding android:id/background to the namespace, Lint complains that it "Cannot Resolve Symbol" even though I am requesting to add it rather than call it. The code works as written, but the error persists. When I change <item android:id="@+android:id/background" to <item android:id="@+id/background", the application stops working (another call breaks). My question is: why does Lint not recognize me adding android:id/background to the namespace even though a call to it functions well? Is there some better way to give this item an id that won't have Lint throw an error?

All three of the namespace definitions for the items in the layer-list below throw a lint error:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+android:id/background"
        android:drawable="@drawable/custom_ratingbar_empty" />
    <item android:id="@+android:id/secondaryProgress"
        android:drawable="@drawable/custom_ratingbar_empty" />
    <item android:id="@+android:id/progress"
        android:drawable="@drawable/custom_ratingbar_filled" />
</layer-list>

I found this and tried running build->clean as suggested with no success.

like image 282
Ethan Keller Avatar asked Jul 27 '15 20:07

Ethan Keller


People also ask

What is Cannot resolve symbol in Android Studio?

Most often “R cannot be resolved” error appears if there is an issue with some of your resource files. Due to this error, you are unable to build your application. That's why we need to solve this error as it not getting away by just doing a simple restart or hitting Alt+Enter.

Why do we use @+ id in Android?

TL;DR: The plus sign in “@+id/” tells Android build tools that you are declaring a new resource. And if it does not exist, add to R. java file. But basically, you don't have to think, just use “@+id/” anywhere you want!

What's the difference between @ID and @+ id?

Exactly from docs: The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource. The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R. java file).

What does Android ID do?

android:id. Resource ID. A unique resource name for the element, which you can use to obtain a reference to the View from your application.


2 Answers

If you are creating your own id:

"@+id/your_new_id"

if you are accessing your already created id

"@id/your_old_id"

if you are trying to access Android's system created id

"@android:id/system_id"

you can see the difference, if you are creating your own id then you have to add +. Since you are accessing system ID so you don't have to add +

like image 189
Sharj Avatar answered Oct 16 '22 14:10

Sharj


It seems you are using an extra +.

You should remove it, replace as follows @+android:id/background to @android:id/background.

like image 28
tato.rodrigo Avatar answered Oct 16 '22 14:10

tato.rodrigo