R.layout.main couldn't be resolved - java

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

Related

IInAppBillingService.java does not generate Java file in Android Studio

I am following this tutorial:
https://developer.android.com/google/play/billing/billing_integrate.html#billing-permission
No InAppBillingActivity file is generating. I'm not sure why. I checked to make sure everything is placed correctly but no luck. Here is what my folder structure looks like:
Click this for picture
Now I know there are similar questions like this but none of them were able to solve my problem. I have already imported googles billing library as well. No file generates when I run / build the app.
The problem is that the docs are not very accurate in specifying where it is that you will find the java file that should be in the gen folder. I had faced the same problem and had broken my head over it, until I found that the .java file was infact generated and it was in the path :
\app\build\generated\source\aidl\debug\com\android\vending\billing\IInAppBillingService.java
Its not a headache issue and your code runs smoothly itself without any interventions required. Hope this helps!
In android studio double click on your package name:
click in New and then on AIDL
Hope it helps
Its usually generated but not put where the tutorial tells you. If you do a Ctrl+N and type in the class name in intelliJ you may be able to find it

"ic_launcher cannot be resolved or is not a field"

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.

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

Android: What's happening to R library and/or ADT 14 in Eclipse?

I've just installed the SDK and all the stuff necessary for programming Android in Eclipse for the first time, and I've just find my first problem. After opening a sample project (Snake, for 2.2), there seem to be errors in the code. Well, the R library was not imported. I don't get why it was not already there, but I've imported it. All good? Nope! text = getString(R.string.tie);still has an error. Same with the rest of code (when it uses R). tie is not recognized, it's not shown in that usual blue of Eclipse.
Eclipse says that the problem is ADT 14... final stuff, or switch statements. Ok... I've read that. There's no switch there. That's not the problem. Eclipse suggests me to change .tie to any other thing... like button1. That's not useful, of course. I think the problem is R class, not ADT. Or maybe R class has some final statement so it is not accepted.
I've tried to see if it was that and, in opening the R.class, I get this message: "The source attacement does not contain the source for the file R.class." What now?
R is not a library, it is a resources file, which is generated automatically during the build from existing resources. Just make sure that resources are properly placed where they belong. Then build the project and everything will be OK.
try using project-->clean in eclipse.
if you imported R library remove it. and try again
Make sure you have the required package installed in the AVD Manager. Then, check your Problems view in Eclipse and look at all other errors, other then the R-related ones and make sure everything else is fixed first. If you have an error anywhere in your XML layouts for example, R will not generated.

Refactoring package name breaks entire app

I am trying to refactor my package using Eclipse
org.sheehan.activity
to
org.sheehan.stocks.activity
For some reason my project just blows up when I do this and R doesn't get regenerated. How can I refactor properly?
UPDATE:
I updated my Android Manifest to reflect the change. R still doesn't get regenerated. Even after a clean. The compiler is complaining about org.sheehan.activity.R
I resolved by:
Android Tools > Rename Package Application
If you renamed properly, all your references across your project should have gotten updated. After doing this, clean your project by going to Project > Clean. This should fix it.
Fixing missing reference to R in eclipse:
Refactor -> Rename`
Build -> Clean
Android Tools -> Fix Project Properties
select the base package of your project in the eclipse package explorer, press F2 (Rename), in the rename dialog: SELECT ALL the checkboxes.:
That should do it
The package name doesn't update in the XML files. Specifically your manifest which needs to know the base package.
For more advanced imports and refactors, literally closing the Eclipse IDE can refresh a cache that causes random errors like "End position lies outside document range" or the "what once worked now doesn't hair puller outter errors."
Signs you should close Eclipse when trying to rename things are:
When you import a project, do some refactoring (like trying to change the package name), then delete the project and try again, you will see immediate R.java errors when you didn't before
When you are importing projects that have manually generated R.java files that have custom imports like "com.ns.proj.R" and don't see the name update in Preview
The box that asks if you want to "Rename subpackages" is checked unexpectedly
the code in the "Preview>>" looks as if it's been complied before instead of black and white code with the proper names replaced
you get XML errors in the manifest activity name like this
android:name="com.ns.proj.CustomCocom.ns.proj.CustomControlse="#android:style/Theme.Light.NoTitleBar"
when it should be
android:name="com.ns.proj.CustomControls"
android:style="Theme.Light.NoTitleBar"
There are too many to name obviously, however this is as important as "keep your eye on the ball" in sports. Something that is so easy to forget, yet things like these apply to other software programs like Dreamweaver (e.g. when you use the Dreamweaver "Put" option instead of FTP dragging with FileZilla and you notice your domain isn't updating your changes online). I called Adobe when I first started as a developer 8 years ago because I knew I wasn't doing anything wrong. They said sometimes the generated files to perform the action get corrupted...in other words, IDE's have bugs too!
In general, close the IDE before you off yourself...it could save your life!
Right click in your Project, go to
Android Tools > Rename Package Application
Sometimes if Project > Clean doesn´t work, so Delete /gen and /bin folders of your project.

Categories