"ic_launcher cannot be resolved or is not a field" - java

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?

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/

Check top line of your activity if have an import of
import android.R
delete it and clean your app.

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..!!!

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.

Related

How can I get stdlib.jar working in Intellij?

After some hours of researching i still have a problem with my stdlib. I've imported lib just like it says on this link (https://intellij-support.jetbrains.com/hc/en-us/community/posts/206850425-How-to-use-a-external-jar-in-a-Java-application) but it still not working. When I type StdDraw.setScale(-100, 100); set scale goes red and intellij says "can't resolve symbol". I'm adding some screenshots so you can see what's the problem. And ignore name of Java classes i'm SLovenian haha ;-)enter image description here
Thanks for your time!
If you tried with project structure > add libraries > stdlib.jar and not working consider this:
I had the same problem and after a deep search I found the reason. You have to use a different stdlib.jar file. Download this stdlib-package and add import edu.princeton.cs.introcs.StdDraw;on the top of your .java file. (you can change StdDraw, Draw, StdIn, etc on top, your compiler will probably help you to import the right libraries)
OK I get it. Just import StdDraw class in src of your project and don't use a package. Then it starts to work fine.

Android Studio throwing warnings on everything

The first project I created since I updated Android Studio to 2.3, I get that everything on MainActivity is marked with a warning. At first I thought it was because I was creating the project inside another folder within AndroidStudioProjects, so I corrected that but still no dice.
Here's a picture of MainActivity:
I get errors like package-info.java file missing or Single class import blablabla, or package name too long (even though I once tried with a very short one) and more.
I updated Android SDK tools but nothing changed. One thing to notice is that previously created projects do work as normal, and even now I keep working on them. Any help would be appreciated
Try to remove support library (replace extends AppCompatActivity to extends Activity). Then Sync Project and Clean
Clean and rebuild your project that may remove your warning problem.

R.java is not created

I've found out that my R.java is never created. I'm using Android Studio and rebuilding does not solve the problem as well.
As far as i can see i don't have any mistakes in my XMLfiles as well.
I'm using W7. The error cannot resolve symbol R resolves.
Please help!
Code can be found here
I have created a new project and copy-pasted your code and it works fine (in Intellij IDEA 12 at least). I have dropped the line (this one android:theme="#style/AppTheme") with theme because you haven't provided code for your theme.
If you haven't added any gfx or other files and you're absolutely sure about the correctness of you theme style, then try to create a new project and do the same I did - code copy & paste.
If you have an error on your any code. No clean/build works to build R.java.
Just check your whole codes fix errors manually (Because of R.java is not builded it will show errors everywhere. So you have to find and fix errors on your own.)
It's usually due to an unaccepted character in the resources names, check for dashes, spaces and caps and let the project refresh

PhoneGap 2.2.0 Android SplashScreen - Throwing error 'splash cannot be resolved or is not a field'

I am new to Java and Android development. I want to show a splashscreen in my PhoneGap 2.2.0 Android App, but when I add
super.setIntegerProperty("splashscreen", R.drawable.splash);
to my main class (extending DroidGap)
Eclipse is throwing the error 'splash cannot be resolved or is not a field'.
R is a class created by the Android SDK when your application is compiled using the resources in the res folder. Ensure the splash image file exists in /res/drawable/splash.png (or required equivalent folders).
NB: The image name must be all in lower case.
R.drawable.splash refers to a file named splash.png in res/drawable (or the resolution specific drawable folders)
Create that file and it will compile correctly.
I'm using Phonegap version 3 and still had the same problem.
Following on from greg84 I feel its very important to note that it is literally looking for a file called splash.png or whatever is defined at:
R.drawable.splash
So if this was
R.drawable.jamie
you'd need to include at *\app\platforms\android\res\drawable\jamie.png
Hopefully this clears up the same 1 and a half hour confusion I just had.
The problem is the package of class 'R' in the code below.
super.setIntegerProperty("splashscreen", R.drawable.splash);
When you ctrl+space on the R, it shows import android.R but you have to import the same package in which you MainActivity.java(assume) is placed.Also defaultly there is no splash variable,you can create a new one and also you can use the pre-defined variable named 'ic_launcher'.Then you line of code will be ->
super.setIntegerProperty("splashscreen", R.drawable.ic_launcher);
Hope the problem will be solved..Cheers

R.layout.main couldn't be resolved

I am building an application and I added a new activity to generate a view. I compiled it. My application can not find anything that is on the format R.id.xxx or R.layout.xxx, I've tried also cleaning my project, closing Eclipse and opening Eclipse again, but nothing. The most strange thing is that before everything was working well. But now it can not recognize even the R.layout.main that is default of my principal activity. Anyone have an idea?
Also I have tried almost everything here: R cannot be resolved - Android error
but no result!
Solved
Thanks to woopsy, also I found the reference to this kind of problem
http://source.android.com/source/using-eclipse.html
it happens because Eclipse sometimes imports R when you press the combination ctrl+shift+O
Remove all your imports for the Activity and then have eclipse fix imports. I have had problems where eclipse wants to import a different R than the one I need.
First of All Check You have R.java File then check
import android.R;
Enter Yourpackages like import com.mypackages.prj;
If you are using eclipse, take a backup of your layout main.xml file and then from the eclipse new file interface create a new "Android XML File" and call it main.xml. copy back from the backup the contents into this new file.
try this.
check your xml files. there might be something wrong in it which is causing R not to build up automatically. To observe such errors, switch your view to Console tab
this is a common error. You need to just search your R.java file in generated section of your project directory in Eclipse. Need to import if the R.java file into the package then import . R;
I hope it will work for you. It was absolutely worked for me...enjoy programming
friends take care that u haven't imported R class, if you have delete "import android.R". The reason is there are two R things one R.java and R.class and we need the java, where we dont need to import rather than referring it. It worked for me and may be to you too.
I found the solution...For me works it
Poject->Properties->Android->Project Build Target (here choose android4.4 or 5.1.1 Android Open Source Project)->Ok
Project->Build All
This function ...
This problem can fix with this process: -
File---->Invalidate cache/restart.
it will restart your android studio and fix that problem

Categories