eclipse, set up android application - android

I'm studying this tutorial now:
http://www.ibm.com/developerworks/opensource/tutorials/os-eclipse-android/
I got an error says "project contains error" when running the code. But I didn't find any error mark in my project. What happened? Thank you very much!

Right Click in your project - Properties - Java Build Path - and then you will see the error, so you just have to delete the error and then clean your project

There is an R.java file in your src directory, and while it used to go there in previous versions (as I just learned), it doesn't belong there any more.
That file is generated by the platform, not you, and should appear in the gen directory.
The copy in your src directory is probably interfering with the real R.java file in your gen directory. Remove the file from src and Eclipse will be happier.

Related

i want to change my sdk path in android adt?

a few days ago i have lost my R.java file from my android app app project from android adt while cleaning it...as it was showing some errors when i was trying to add the feature of ads in my xml file...now i am unable to recover my R.java file in the project .
I have tried many options such as:-
cleaning the project .
checking for errors in the xml file and corrected and tried to clean the project once again.
copied and pasted the res,gen and android manifest.xml file in the new project of the same in another workspace and pasting the new R.java file generated over there into the actual workspace but still its not working and showing errors.
i tried to cut and paste the sdkmanager.exe from the actual folder to some folder elsewhere and tried to clean the project again to regain its R.java file but it is still not working and the sdk manager is showing the same path even though i have shifted it somewhere else...
now what am i supposed to do...
To change SDK path: Window/Preferences/Android.. and then Set SDK Location
R.java is an auto generated file and it's error is based on errors in Manifest file or resources , maybe there is an unnamed string in your string file ,if you can, post your R.java file errors. and for changing sdk path its through Window -> Preferences - > Android .
On Windows : Window > Preferences > Android. Then click on "Browse" to change SDK path.
On Mac : ADT > Preferences > Android and "Browse"
You need to provide your R.java file errors mine was R cannot be resolved to a variable and I had to go to project properties -> java build path, then make sure your libraries are selected and clean and build and if that doesn't work delete your bin and gen folder and clean and build...Hope this works for you good luck!

Class not found exception on android

I get some soure from net. and import on my workspace. When i run on emulator, its throws,
"05-28 17:30:47.895: E/AndroidRuntime(840): java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.developmentmill.laserlogic/com.developmentmill.laserlogic.StageActivity}:
java.lang.ClassNotFoundException: com.developmentmill.laserlogic.StageActivity in
loader dalvik.system.PathClassLoader[/data/app/com.developmentmill.laserlogic-2.apk]"
But when i run the same code on my friend machine, its running without any error.
My eclipse ADT Version is 17.0 my friend eclipse ADT version is 16.0
I copy the jar files from lib folder to libs foder. and change the java build path from lib to libs folder. and also i cleaned the project.
Again, i run the project, the same error has been throw.
What is the problem and how to correct it? y its occur on my machine only. Pls help me.
I have also faced this problem.
so try this.
Right click on project -> goto properties -> Java buid path -> libraries -> remove all External Jars from here -> press OK
also remove all jars from libs folder
clean project -> restart eclipse.
Then again put all required jars in libs folder.
I have solved my problem by this
hope this will help you....
First create libs folder in your project and then add all jar file or library file used in project in libs folder and now run your project.
It will definitely run.
What worked for me was:
I already had a libs folder in the same hierarchy as my src & res folders.
The FlurryAgent.jar file was saved on my Desktop. I simply right clicked on the FlurryAgent file, copied it. Then I pasted the file into the libs folder in Eclipse.
Eclipse automatically copied the FlurryAgent.jar file into the “Android Dependencies” folder also.

Eclipse Android gen already exists but is not a source folder

I am getting the following errors when I try to load an Android project in Eclipse that was working just fine last week.
Any ideas?
[2012-03-16 09:29:43 - MyProject] /MyProjectName/gen already exists but is not a source folder. Convert to a source folder or rename it
Note that I have tried to clean the project several times, even restarted but it still gives me this errors.
right click on project and go to project properties, then goto java build path, and then in source tab, click on add folder button and add gen folder.
just src and gen folders should be checked there if you haven't any library projects attached.
MyProject] /MyProjectName/gen already exists but is not a source folder. Convert to a source folder or rename it
This problem happens when eclipse does not able to find each linked contents in a project.
For example:
When we import a project to eclipse from a specific folder(suppose D://NewFolder), eclipse memorized and link each content with its appropriate path (which is D://NewFolder/project_library/src in our example).
But if we replaced(Here D://NewFolder To E://Another_Folder) or delete the library from its specific folder(Here D://NewFolder), eclipse unable to find its(project_library) original path
and give red error.
So when this problem happens, first we have to make sure that the imported project or library is its original folder and no changes has made to this.
Otherwise again replace the project to its specific folder to which eclipse has linked at the time of import i.e parent folder.
This happens because your .classpath file got wiped out somehow. This file contains all the information from the Java Build Path tab under Project Properties. You could add in all information manually but there's an easier way of fixing this problem.
If you have a copy of the .classpath file on your machine, you can just copy and paste it into your project directory.
Follow these steps in Eclipse :
Project -> Properties -> Select Java Build Path ->
Open Source tab -> Click Add Folder and check the gen

Eclipse - ACRA jar file not recognised

I'm trying to add ACRA to my project and I've followed these steps ACRA Basic Setup but Eclipse is not recognising the #ReportCrashes that it has you create with the class:
I made sure I created a "lib" folder and I added the jar file to it (by drag & drop from a windows explorer), I then right-clicked it and choose Add to Build Path. I even tried to remove the jar file and re-add it and do a Project --> Clean but still nothing.
Any ideas as to what I'm doing wrong?
Here's some screenshots of the Annotations from Eclipse:
I've had the same problem, and I think I've discovered the root of it: I was importing the jar inside SRC folder, instead of importing the one in BUILD folder. Just deleted the first one, reconfigured BUILDPATH to remove the wrong entry, did a clean, copied the right (BUILD FOLDER) jar into the libs folder in my project and then everything went OK
Maybe it helps?
OK I figured out the problem. I had the same issue as you and the problem for me was that I added the source jar and not the build jar from the ACRA archive. It now recognizes the classes from the jar. Rookie mistake :)
Robert,
I updated to R20 of the Android SDK Tools today (Aug 15, 2012) and also upgraded to Eclipse Juno and had similar problems with ACRA and my other jar files.
The way I understand it R17 change the build process that any jar in the '/libs' folder is automatically added to the build path. Which means if you had a jar in the '/libs' folder you need to remove it from you java build path or you get the dreaded "Dalvik 1" build error.
Next, I noticed there is no way to add source or javadoc to jars in the lib folder. So I moved all my jars to a second folder, in my case '/external/jar'. When I moved ACRA-4.2.3.jar to '/external/jar' my project would crash with the same error as yours. So I moved it back to '/libs' and it worked, although I could not add javadoc or source to the ACRA jar.
The conclusion is to place the ACRA jar file in the '/libs' folder. Other jar files may be placed in '/libs' or elsewhere. Also, update Android SDK and Eclipse.
Hope this helps you are somebody,
Fish

R.java disappears after project clean

After I added some .png files into my Project Workspace drawable folder I refreshed my drawable folders in Eclipse and the newly added files showed up. But when I tried to access those resources using R.drawable.xyzimage, xyzimage although in the folder could not be resolved.
So I did a Project Clean and guess what after this clean R.java is totally gone and all my classes accessing resources using R.java is showing all sorts of error and Eclipse won't let me run the code anymore.
I have backup of my source code but I want to explore if R.java can be regenerated and how?
Thanks for all the help.
Try Project->Clean in Eclipse. In my limited experience if R.java is not being automatically created then there is an error somewhere in your xml. Triple check everything.
You have to build the project to be able to use the newly added resources.
Cleaning a project removes all auto-generated files. Building the project it should automatically create them. When you Clean a project, there's an option to start a build immediately after clean up.
Here's a few things you can try (did the same procedure after manually deleting the "gen" directory.
After you have deleted the gen directory, go to Project > Clean ...
You should have errors indicating that R cannot be resolved to a variable. Right click on your project from the Package Explorer and select Build Project. Be sure Build Automatically option is turned off (uncheck in Project > Build Automatically).
Errors regarding R should have now disappeared. Now, perform a Project Clean once again. All errors should be gone.
Let me know if this works for you.
Here is what the problem was. I added those new png images to the project and android has rules as to what characters are allowed in the names of these images. Once I changed the uppercase letters in the image name, it was back on track again and Build Automatically generated the R.java file and all errors were gone. Eclipse console is the place where I found all the errors related to my resources.
Thanks Guys....I tried your solutions but my error was something specific which was due to my image naming convention so this is the way I fixed it.
I would agree this is usually a XML problem but moreover that it is something within your res folder that is the problem and may be highlighted with a red cross after the clean attempt.
I have just had this problem and it was because I had created my own folder called 'data' within res folder. After the clean it had a little red cross against it. I removed this folder and R built again.
Regards,
Mark
Several things you should check in your project:
Check the Problems tab in your Eclipse IDE. Are you sure that you did not introduced building problems while making changes with drawables? To check that you need to check xml source of affected layout and see if something is marked red.
In File explorer go to the directory where your Android project is. Check that you have file default.properties (.classpath, .project and AndroidManifest.xml should be there). If default.properties is missing it may be easily replaced by correct version.
Which is the Android version you are working with? If that is 1.5 or lower be sure that in the res directory you have directory named drawable, not drawable-hdpi, drawable-mdpi and drawable-ldpi. Last three are valid for version 1.6 and higher.
Right click on your project in Package explorer in Eclipse. You will get a number of options. Go to Android Tools-> Fix Project Properties so see if that helps.
I had an invalid jpg in my res/drawable folder. I removed the jpg and it worked.
I had this problem on my Mac too and I think it could be good to know for all Mac users how I managed to solve this error.
I had a .DSStore file automatically imported to my project inside the res directory and when I removed it and rebuilt the project all went well.
Everytime you clean the project and it rebuilds, it imports
import.android.R
so, delete this import and remove all errors from xml files. It will work.
This happens to me if I move my project to a new location. I have found that the answers above didn't fix my problem, but that creating a new project and importing the source did.
This may be simple but check to make sure you don't use
import android.R;
If you add an external resource file with capital letters for example
"Hello.png or WelcomeSound.mp3 etc etc" like if you add upper case letters and clean your project you'd surely loose your R.java file. So if you already lost it, either rename the file externally and then clean your project or else right click on the project Refractor->Rename and then rename your file with all letters in lower casing. Next, delete the 'gen' folder in the project explorer and now right click and "Build Project". If Build Project option is grayed out, go to Project-> Deselect "Build Automatically" option.
Regards,
Kshitij Thube
Check at the Console View If there in message Error, It will Help you to find out the source of the probleme.
I had i similar probleme and i find out that the probleme was from the pic name even if the name respect the Syntax so I change it to img1 and it worked fine.
Try editing one line of code in your project, then build the project once more.
Another thing: never try to run an application with the texteditor opened with a xml file. That will create a wierd run configuration that can only be fixed by project clean-up and sometimes can make the xml file to vanish (happened to me twice already).
All my R.* files stopped working after I did a Project->clean in Eclipse. The issue was that I backed up a XML file attached to one of my activities in the layout directory. This causes errors in every activity of my project.
After deleting the file I still had R errors in one of my Activities and it only was resolved after I tried importing different files and then deleting them. I actually made no change to the previous imports but for some reason deleting them all and re-pasting them fixed it.
I have got the same problem after lots of cleaning and building project again and again. I found that on console there is this error:
res/drawable-hdpi/Blue Blank.png: Invalid file name: must contain only [a-z0-9_.]
and this is not appearing as an error in xml. I changed the name and save the file, clean project and build. Now it's working. My suggestion check your res folder and name of files you use in it and name only [a-z0-9_.].
Delete related tag in xml, save xml, clean project, build project. Now again put that resource in xml and save!
Check your file in drawable folder ensure that all are resource file (image) remove unwanted file Like thumb.db. Remove those all files and check again
Make sure your png files have lowercase names. That is what kept throwing mine out, because I capitalized the first letter, or I used an unallowed non alpha numeric in the naming. Check that before destroying any of your code.
just check your image folder (usually created res > drawable files) and be sure dont use capital letters on .png files, every type must be in small letters then you can find again your R.java under the gen file folder
i removed 'import android.R;' then commented out the offending lines, then did a build, ok
then i removed the comment and it fixed it
I had the same problem when I cleaned my project. I got crazy to solve it, I searched and searched but solved it in my way.
First of all, delete all needless files in your /res folder. I had some notes in it, I took them to another project that I don't work on it and build the project manually. It worked! Try this I'm sure it will help.
Good developing!
Was there an XML file with the naming convention of "somthing.out.xml" generated? If so you should delete this file (an unwanted file of this name can cause major problems for your somthing.somthing.R file import).
In some versions of eclipse (I know eclipse javaEE does this for sure), running the project while viewing an XML file will create a file called filename.out.xml in your res->layout folder. You must delete this generated file if this has occurred otherwise you wont be able to get the java.R file to import.
Try Project -> check Build Automatically
If you are using 64-bit Ubuntu, try to install the 32-bit libraries (ia32-libs)
$ sudo apt-get install ia32-libs
it worked for me
This exact same thing happened to me. coincidentally I needed to update my adk that day, so i did so and after restarting eclipse it worked again. My recommendation would be to build the project and restart eclipse. It is not due to any error in your code.
I read and tried many of the above after simply doing a clean on one project. Eclipse would not build anything afterwards.
Fortunately I had last-nights backup of the workspace and my source is copied in from VS 2010.
No more cleaning!
Delete your project from workspace witout source deleting and then import it into workspace.
RightClick on your Project -> Delete /Don't select "Delete project content on disk (cannot be undone)"/ -> Ok
File -> Import -> General -> Existing Projects into Workspace -> Brouse -> /Look for your workspace(!) folder/ -> Ok -> /your cleaned project will be automatically checked/ -> Finish
I had the dreaded missing R problem yesterday with Eclipse Juno after a routine clean. StackExchange is full of suggestions and extensive googling revealed only the usual suspects (XML naming conventions problems, etc) none of which seemed to apply directly, although it is certainly possible I missed something.
The best summary comprehensive list of possible causes and fixes was here:
http://www.techrepublic.com/blog/software-engineer/a-comprehensive-troubleshooting-guide-for-androids-r-cannot-be-resolved-error/
One useful tip there was to try to create and run a simple "Hello World" in my workspace. If that does not run, the setup is corrupted. My Hello World was just as full of errors as my custom app.
The solution that worked for me (perhaps great overkill but nothing else worked) was to completely uninstall Android SDK and delete Eclipse (Juno), download Eclipse for Developers (Kepler) and reinstall Android ADT plugin and ADK and recreated my AVDs using the latest "compile with" version in options.
So far so good, although I am recreating the app from scratch. I will be more cautious about using clean from here on.
I have same problem occur just now I renamed invalid png file like *demo.1.png as demo.png * and its work.
Proven successful method, check the file (AndroidManifest.xml) and delete all comments in it, and make sure there are no errors in this file, I tried and did work with me.

Categories

Resources