In every instance in all of my classes where I reference R.id.something
, the R
is in red and it says "cannot resolve symbol R". Also every time there is R.layout.something
it is underlined in red and says "cannot resolve method setContentView(?)". The project always builds fine. It is annoying to see this all the time. I have read many other questions on here about something similar but most involved importing projects from Eclipse. I am using what I believe to be the most recent version of Android Studio and the project was created with Android Studio and worked without any "cannot resolve R" problems. I would like to know what causes this if anyone knows.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
I had to import my
R
package in android studio. For ex:import com.example.<package name>.R
Your code is just scrambled. The answer is fairly simple.
Just go to **Build** --> **Clean Project**.
That should do the trick.
I'm current using Android Studio 3.0.1.
If you see this error after moving java files or directories to other locations, then you can guarantee that Android Studio has gotten confused. And guess what? undo-ing those actions doesn't fix the problem.
So you try a clean, but that doesn't work.
And restarting doesn't work either.
But try File -> Invalidate Caches / Restart... -> Invalidate and Restart
Android Studio maintains information about which files are dependent on which other files. And since moving files around is not implemented correctly, moving files causes errors. And that's not all: caches of these dependencies are used in an attempt to speed up the build.
This means you not only have to restart, but you need to invalidate those caches to restore (or more accurately, rebuild) sanity.
I had the same problem and most times it is resolved by
But this time the error persisted even after doing all these things and at last i found the culprit.
The problem was in an xml file, where i have given ordinary string value for an
android:id
instead of an id resource type.MISTAKE
CORRECTION
NOTE
In most cases the compiler shows you the source of error in the Message. Try to check it first before attempting other solutions
There seems to be many causes for this issue. Recently, I added an activity to test with called NewActivity. This created a file called
res/menu/new.xml
and gradle did not like that name because new is a reserved word.or
Those are definitely good things to try, but you may have some other issues you need to resolve before you run those commands.
I recently had this issue and the clean/build etc. didn't resolve it. I guessed I had an issue somewhere but wasn't sure where to look to find it (was it in the manifest, resource xml files etc?).
When something is wrong, you can find out what it is by doing a code analysis run.
From the menu at the top choose:
Analyze -> Inspect code, scan the whole project using the 'Default' profile.
Your inspection results will contain an element called 'Android'. In here you will get a list of anything that is causing issues in your resources and manifest file. The errors will open up the generated xml files from your build which will show any errors in red.
My exact issue was caused because I was using flavour based manifest files and I copied some permissions inside the
<application>
tag in the flavour by accident.UPDATE: I did have an issue after where Android Studio still showed the error after the fix, even though I could now build and run perfectly fine while the error was still there. (I am running a canary build so putting it down to that for now)