Ants
Ants

Reputation: 390

Android: Cannot find symbol variable error

I am running into a weird issue! I have id names for each layout in my xml file and I created variable references to them in my main activity . java file.

When I clean and rebuild my project I get this:

"error: cannot find symbol layoutMain = findViewById(R.id.layoutMain);"

no idea why.... first time I see this...

I am using min. SDK 21, target of 29

see images: MAIN ACTIVITY JAVA

GRADLE

XML MAIN ACTIVITY

Upvotes: 1

Views: 2862

Answers (3)

I hope it's not too late. This may be happening because there are two versions of the xml layout (one for day, another for night, for example), but the item was included in only one of them

Upvotes: 1

Ar Tero
Ar Tero

Reputation: 1

Also, nothing helped. I deleted the cache, rebuilt the project, changed the names. The solution for me was to create a new project and just copy everything from the old one.

Upvotes: 0

Gabriel
Gabriel

Reputation: 474

Probably Android Studio bugged and is having problems with ids.

Try to Invalidate caches and restart. Go to File > Invalidate Caches / Restart > Invalidate caches and restart

This will delete Android Studio caches and recreate them.

Upvotes: 1

Related Questions