1

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

5
  • Does this answer your question ? stackoverflow.com/questions/18991161/… Commented Mar 18, 2020 at 22:10
  • Yes, usually an issue with cached ids. Invalidate cache and restart often helps. Commented Mar 18, 2020 at 23:03
  • Why do you have 2 implementation "com.google.android.material..." ? try to comment the alpha one Commented Mar 18, 2020 at 23:12
  • I was desperately hoping that, that would solve my issue! but didn't.... I created a dummy android app with the same programming and it worked... SO WEIRD! I also removed the implementation but didn't do anything Commented Mar 19, 2020 at 3:56
  • I just realized that I have 2 layouts called "main_activity" 1 is the original and the other is (v21), could that be causing the issue??? Commented Mar 19, 2020 at 14:33

4 Answers 4

1

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.

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

6 Comments

I was desperately hoping that, that would solve my issue! but didn't.... I created a dummy android app with the same programming and it worked... SO WEIRD!
Oh okay. Sometimes this happens, maybe some corrupted files. If this happens again try to import your project by Import an existing project option in Android Studio. This worked for me sometimes.
I just realized that I have 2 layouts called "main_activity" 1 is the original and the other is (v21), could that be causing the issue???
I don't thinks so. One question, do you have this problem on other android studio projects?
no. any way I just started from scratch and it works as intended! thank you for putting up with me!
|
1

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

Comments

0

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.

Comments

0

If you are seeing these issues after a cache invalidation - something is seriously wrong.

In my case it was Mockito tests which could not start because of a conflict between Java and Kotlin code (value class).

Conversion of tests to Kotlin helped.

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.