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

Ants
  • 390
  • 1
  • 3
  • 18
  • Does this answer your question ? https://stackoverflow.com/questions/18991161/android-studio-cannot-resolve-symbol-but-code-executes-correctly – M A Salman Mar 18 '20 at 22:10
  • Yes, usually an issue with cached ids. `Invalidate cache and restart` often helps. – Cory Roy Mar 18 '20 at 23:03
  • Why do you have 2 `implementation "com.google.android.material..."` ? try to comment the alpha one – Biscuit Mar 18 '20 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 – Ants Mar 19 '20 at 03: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??? – Ants Mar 19 '20 at 14:33

2 Answers2

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.

Gabriel
  • 464
  • 4
  • 17
  • 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! – Ants Mar 19 '20 at 03:54
  • 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. – Gabriel Mar 19 '20 at 10:06
  • 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??? – Ants Mar 19 '20 at 14:33
  • I don't thinks so. One question, do you have this problem on other android studio projects? – Gabriel Mar 19 '20 at 16:26
  • no. any way I just started from scratch and it works as intended! thank you for putting up with me! – Ants Mar 19 '20 at 18:04
  • Yes, I was going to tell you to do this. The last thing to do is to create a new project and copy all your files. Or to import your existing project. Good programming! :) – Gabriel Mar 19 '20 at 18:06
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.

Ar Tero
  • 1
  • 2