"ic_launcher cannot be resolved or is not a field"

I followed the Android tutorial and when everything was done, I had a problem with this code:

getDrawable(R.drawable.ic_launcher); 

And I got a message

 **"ic_launcher cannot be resolved or is not a field"** 

What's more, my icon does not appear in the tablet emulator, but it starts automatically. What's happening?

+6
source share
4 answers

replace "mipmap" with "drawable"

I had the same problem as after the tutorial, and I found out that my AndroidManifest.xml file has the following code: -

android:icon="@mipmap/ic_launcher

so I changed R.drawable to R.mipmap and solved the problem. Wherever I find out, I replaced it with mipmap. It is good to check mipmap with android studio 1.1. for more information: - https://androidbycode.wordpress.com/2015/02/14/goodbye-launcher-drawables-hello-mipmaps/

+11
source

You should check to see if dir gen file named R.java . If so, open and check if there is an icon attribute.

Perhaps you transferred your project or copied something from other projects. In any case, you can delete the file manually in gen and let Eclipse recreate them. If not, you can go under Projects and then Clean to select your project. It should work.

OR

I just thought I'd add a quick additional answer on this topic. I am very new to Android development and found that one of my classes did not compile because I could not find any of my available attributes. In the end, I traced the problem to the point that the class imported android.R (automatically added to the Eclipse import list). Once this line has been output, the class is compiled.

0
source

This is how I solved the problem:

There was android.R import in my program, so it gave an error for R.drawable.ic_launcher .... removing android.R import worked for me .. !!!

0
source

Check the top line of your activity if there is import

import android.R

delete it and clean the application.

0
source

Source: https://habr.com/ru/post/955994/


All Articles