Reputation: 71
I was following a tutorial of Android and When I was done everything, I got a problem in this code:
getDrawable(R.drawable.ic_launcher);
And I got the message
**"ic_launcher cannot be resolved or is not a field"**
What's more, my icon doesn't appear in tablet emulator, but starts automatic. What's going on?
Upvotes: 7
Views: 11152
Reputation: 361
replace "mipmap" with "drawable"
I had the same problem while following a tutorial and i found out that my AndroidManifest.xml file had the following code :-
android:icon="@mipmap/ic_launcher
so I changed R.drawable to R.mipmap it solved the problem . Wherever I found out drawable I replaced it with mipmap. Good to check for mipmap with android studio 1.1. for more info :-https://androidbycode.wordpress.com/2015/02/14/goodbye-launcher-drawables-hello-mipmaps/
Upvotes: 12
Reputation: 1081
Check top line of your activity if have an import of
import android.R
delete it and clean your app.
Upvotes: 3
Reputation: 11
Here is how I solved the problem:
In my program there had been android.R import so it was giving error for R.drawable.ic_launcher ....removing android.R import worked for me..!!!
Upvotes: 1
Reputation: 1
You should check if under the dir gen
there's a file called R.java
. If so open it and check if there's an attribute called icon
.
It could be that you moved your project or copied something from other projects. In any case you can remove the file manually under gen
and let Eclipse recreate them. If not, you can go under Projects
and then Clean
choosing your project. It should work.
OR
I just thought I would add a quick additional answer to this topic. I am very new to Android development and had found that one of my classes was not compiling as it could not find any of my drawable attributes. In the end I tracked the problem down to the fact that the class was importing android.R
(automatically added to the imports list by Eclipse). As soon as that line was taken out, the class compiled.
Upvotes: 0