R.java's values not recognized - android

I downloaded a an android project folder from a friend (the app works). In eclipse, I created a new Android project from existing code. However, there are errors at the lines calling the layouts/ids from R.java. Example: R.layout.my_layout
I tried cleaning the project, and deleting the project and creating it again. The code should be working. I checked R.java to make the sure the name matches. Note that I am an advanced-beginner at Android, so I know the basics. Please help, thanks.

if you downloaded the project from a friend, you shouldn't be creating a completely new project, but choose "new project from existing source".
try looking in the project properties under Android, many times, the import screws up the properties and moves the target SDK to the lowest possible and you'll need to change that"

it sounds stupid- but try clearing you project, make a simple change in code, save and rebuild.
i hope that'll fix your problem,
another thing- make sure u didnt imported any android.R.### class - if u did erase those lines.
Wops.

What errors are you getting in console from eclipse? Error messages are usually need to help. My only suggestion without seeing the build errors is to check your import statements. Sometimes eclipse inserts bogus import to the R classes.

Related

My R class is not creating ids of my UI elements

This is the image of my main_avtivity:
This is the image of my activity_main.xml layout:
I have imported com.example.calculator.R class. I even tried to clean the project so many times. I even made a new Project two times. Moreover my ADT Plugin is properly installed. Plz help me. I have done everything mentioned in other StackOverflow answers but nothing seems to be working for me.
R.java won't generate properly if there are errors in your XML files. So look through your XML files and look for any possible issues. The errors in the console at the bottom of your second screenshot would be a good place to start.
First SaveAll your changes then go to project>Clean Project and Build it again. Its seems like you didn't save your project.

Android ActionBarCompat Not working from the start

OK, I have been wanting to try the new ActionBarCompat, however, I am not able to run my programs in the emulator.
I have been trying to implement the following: http://antonioleiva.com/actionbarcompat-how-to-use.
and have been stuck on basically the first part. However, working with the author of that content, I was able to get further as I was not adding the project under sdk\extras\android\support\v7\appcompat folder like stated. However, I still think that might be the reason I cannot do this...
More detail can be found here: http://antonioleiva.com/actionbarcompat-how-to-use/#comment-43
Basically, on my first attempt, I just created an Android project, and changed the source code as indicated. Code would not run on the emulator. So I went back to the original code, and that ran on the emulator.
Checked online, found out I might need to add the \extras\android\support\v7\appcompat folder as a library to the project I am building. So I added that and a new android project was created. There were build errors from the start, but I failed at trying to add it as a library to my project, and deleted it....thinking this was way overboard.
After back and forth chats with author of linked website, I found out I had to do that overboard thing.
So I tried the following link to the T: (I cannot post more than 2 links due to low repuation...I will add this link as a comment below)
However, Eclipse would not allow me to add the appcompat Existing Android Project...but it did allow me to add the appcompat Existing (General) Project. I think this may be some of the problems??
Right now, I cannot run the project at all. Eclipse is showing a red exclamation mark on the project folder, but all the code seems to be fine. So I don't know what to do now...I recreated this project several times over, and this one was the one where I knew what to do...and I am still getting problems
So...
I decided to move to Android Studio...updated the IDE, updated the SDK manager to include the new support library, and other things. Created a new project, added to the build.gradle file as shown in the link provided below in the comment. I ran the ant build, and then built the project...tried to import the right things to allow ActionBarActivity, but I could not get that far.
I can import
"android.support.v7.*"
"android.support.vy.R" // and all folders within
but nothing allows me to add ActionBarActivity, and I don't know why.
FYI, I guess I would prefer a solution to Ecplise, as it seems like I actually got somewhere with it.
The best example to use is from here, and I would follow it closely. I had similiar issues when I first came across this. Problem was I misunderstood what I needed to do
http://developer.android.com/tools/support-library/setup.html#libs-with-res

Android - Cannot import google-play-services_lib because the project name is in use

I know that there are two post like this one in Stackoverflow (this and this) but I already tried what is described there without any result and I have the feeling that I'm running out of options.
This screenshot is from one of these two posts, but is exactly what I also see.
In my case, I was never able to make the googlemaps work and I tried to import and copy the stuff in so many different ways that I guess is what lead to the actual situation. In my last attempt, I was going to try to follow the steps described in this post, which seems to be the most accurate one, but as I said, now I just can't import the google-play-services_lib because keeps telling me that is in use.
I made sure that I deleted the project from my workspace and any other place where it could be stored by searching for it.
Does anyone have an idea that is not described in the other two posts? Creating a new workspace and importing my project and then the google-play-services_lib could be a solution or the problem is of another nature? Is there a way of obtaining more information about the error shown by Eclipse in order to fix it?
project name already exist on workspace most of time may be named as mainactivity (or other name) try to rename change existing project name and after try to import it!
e.g following steps
first screen shot shows your same error
after click select all button shows actual error explains below screen shot:
note this screenshot error message is Cannot import MainActivity because the project name is in use after shows project name rename on existing workspace on your eclipse after try again import it will work perfectly!
google-playservices.lib is in use by another Project.
Check following
close the project who is using it with right click close
remove the reference from the project who is using it.
I you don't have the library project in your eclipse works space and you still receive this message, you can just close eclipse, go to you workspace folder and manually delete the google-play-service library from there. then open eclipse and try to add the project again.
I'm sure there are better ways to do it, but I ended up creating a new workspace, importing my project and then importing the google-play-services_lib.

Android R.java disappeared after reference to facebook

I followed the instructions by the facebook, everything is good before adding reference to the facebook library. As mentioned in the title, the R.java just disappeared, making the whole project unable to run.
I tried to delete the gen folder, cleaned the project, rebuilt it, but it did no good.
The project runs without facebook, but I have to implement the facebook function to get the project done. Anyone could help?
it is probably that there are now two R.java, one in your project and the other one in facebook. Try to manually put the import back, like, com.yourpackage.R and see if that fixes the problem.

Eclipse hangs when trying to add menu.xml

I've recently starting developing with the android sdk. Currently, I am trying to add code to use a menu, however, when I try to add a menu.xml under res/menu, Eclipse hangs and freezes every time. When I reopen the Eclipse, menu.xml is there, but every time I try to open it, Eclipse hangs and freezes again.
I am running on OS X Snow Leopard, Eclipse 3.6.2 and the latest android sdk and adt plugin.
Any help, insight, thoughts?? I am thoroughly stuck.
Thanks.
Dustin
Thanks for the input guys. What ended up working for me was instead of trying to manually create a new menu.xml file, I find the add android .xml wizard and using it instead allowed me to add whatever I needed with out any hang ups.
Same problem happens for me even under the latest version of Eclipse (Helios). If I wait long enough, Eclipse reports a stack overflow exception and then this shows up in the Output window:
W/ResourceType( 5124): Bad XML block: header size 0 or total size 9949440 is larger than data size 0
menu.xml:1: error: Error parsing XML: no element found
This indicates that the XML parser isn't handling empty documents and the Android menu editor is barfing on the newly created file while trying to open it. I'm sure there is some "standard" way of creating a new menu that doesn't break the IDE but I have no idea what that method is. I'm too used to editing my files by hand but this crash/hang bug is a serious nuisance.
Dustin,
I think what has happened is, your settings have become corrupt. I highly recommend resetting all your settings. Keep in mind, you will have to re-import all your projects so this can be quite a pain, but I really think this will fix your problem.
To start, find your workspace folder and rename it to something like "workspace-bad"
Then, create an empty workspace folder to replace the one you just renamed.
Lastly, open eclipse and it will act just like a brand-new installation.
You will need to re-import your projects, which can be done by going to eclipse, hitting File>Import...
Then select under General
"Existing Projects into Workspace"
then hit "Next" and then hit "Browse" to find the root directory
also make sure "Copy project into workspace" is checked
I also recommend doing your "problem project" first, that way you don't waste your time doing the rest and then find out you have to re-create it.
I'm hoping that fixes it for you, good luck! :-)
-Jared
I ran into the same issue with the same setup. Right clicking menu.xml, selecting 'Open With', and selecting Xml Editor seemed to be a viable workaround for me.

Categories

Resources