Android: NoClassDefFound - android

I have an Android project that's using SubVersion. I've used Subclipse to import the project into my Eclipse Wordspace.
Now I have a problem with getting a:
java.lang.NoClassDefFoundError
The class I'm trying to import is located in the same package, and it's not an activity, so I have not added it to the manifest file (though I did try with no effect).
It looks like an issue with classpath etc, but I'm not quite sure how to go about fixing this?
Any help is much appreciated, thanks!

Try to create a new android project, copy all your files there. Then make sure your class path are correct.
Lastly, Project>Clean. Make sure you didn't import any R.
Edit:
If that doesn't work, you may want to double check you fields, static blocks.
java.lang.NoClassDefFoundError
Will be thrown if your class failed at initialize.

Related

The import com.example.myfirstapp.R can not be resolved

I have been working my way through the Tab menu tutorial and have come across multiple errors. After doing some research on here I found the common solution was to change the Import android.R to import com.example.myfirstapp.R.
This is giving me the error that this file cannot be resolved. Can anyone tell me why I can't import this file? I have a hunch from researching on here that eclipse has not built the file, but I have no idea how to build it as I am new to coding as this is just a hunch and may be completely wrong.
package com.example.myfirstapp;
[Edit}
i have removed the "com.example.myfirstapp.R" and have CMD-SIFT-O to restore the imports but i still have the following errors.
You don't need the com.example.myfirstapp.R unless it is in a library. If it is in com.example.myfirstapp, remove it.
Also, trying cleaning your project and rebuilding it.
Make sure you don't have any files, pictures, etc in your drawable or assets folder with capital letters, spaces, or dashes. Just use plane old lowercase. Also, try to clean your project. Go to project > clean. Then restart eclipse. Hope this helps. Also eclipse won't reconize any changes in XML files without saving first. Make sure to save after you add a button, ect.

Errors in imported library

I want to use this library to crop images, since the crop intent can cause problems on certain devices: https://github.com/lvillani/android-cropimage
If I import it in Eclipse however, I get some errors in Eclipse.
In the Util class I get an error on this
options.inNativeAlloc = true;
inNativeAlloc cannot be resolved. Also I get another error in the CropImage class:
MenuHelper.showStorageToast(this);
The MenuHelper class isn't included in the library.
Since if seen these kind of errors on another library I want to know if there is something that I'm missing or doing wrong.
I'm saving the library as a zip file, extract the zipfile and import the library folder in Eclipse by using import > Existing Android Code into Workspace. I think this is ok since I checked the source on Github to comfirm if I'm missing something.
This isn't a new issue for the project as you can see on the issue page. To solve it you could follow the recommendations made in that post or you could download/get the develop(the same way) branch which, at a quick look, doesn't seem to have those problems.
The project that you are using already is an android library. You should just download the entire source folder and use Import existing project (the .project file is already in github).
Then in your own project create a reference to it by going into project properties -> android -> library -> add
About inNativeAlloc - it is a hidden field... To set a "true" value to it you must use this code: setInNativeAllocTrue(opts)

R cannot be Resolved To a Variable only in one line

My friend created an android application using phonegap, jquery and facebook sdk in eclipse. I wanted to run the application in my computer. So I imported the whole project into eclipse. I downloaded all the necessary APIs. Initially I got a lot of errors, but I solved most of them.
Now I am stuck with just one error. And it is in the src/com.facebook.android./FbDialog.java file. One particular line
Drawable crossDrawable = getContext().getResources().getDrawable(R.drawable.close);
gives the error R cannot be resolved to a variable.
I have gone through a lot of similar questions on this website as well as other websites. I have cleaned the project innumerable times. The R.java file builds successfully. Also, my friend is not getting any error when he runs the same project in his laptop. So I don't think there is any problem with the coding part.
I am definitely missing some important setting or download. Please help. This one error is giving me a lot of headaches.
I am a new user her so cant upload a screenshot.
1st. res/drawable folders (ldpi, mdpi, hdpi) must contain an image named close, if not add it. I doesn't really mater, in order to overcome the error, in which of them the file exist.
But in order to use resourses properly see the Android documentation here
2nd. File FbDialog.java must have an import of the R.java sometimes the R imports get mixed with clean & built and instead of import your.package.com.R; it is included the import android.R;
Depending on the dependency libraries or related projects of main project the close file resource may be a part of an other library in that case you will need import that.package.com.R;. So if it is part of Facebook SDK then you will need import com.facebook.android.R;
I hope you get the logic of how R imports work.
Update: Lets force it to work, change line to:
Drawable crossDrawable = getContext().getResources().getDrawable(your.package.com.R.drawable.close);

android eclipse adding folder to project

i have an android project which has a lot of classes I've built.
i want to organize it to sub folders and my package in eclipse.
when i'm adding a folder and move files over there, what changes should i do in the code so the file which need this classes can reference to it?
is it something in the:
import android.app_name.folder_name.class_name
help will be appreciated, my project is beginning to be a big mass..
if its not possible i will be glad to hear about other solution
Eclipse has a rename/refactor method you can use. The only issue I'm familiar with is the fact that it seems to break the manifest.xml
Yes you can import project into Eclipse...
Then you should create a Package to manage related classes. (FYI, package is ultimately creates folder hierarchy on your drive).
Note: Make sure you provide a correct reference of the particular class in AndroidManifest.xml file.

Android Dev - R.layout.main , Variable 'R' cannot be resolved

We are new to Android and we are trying to develop a new application. We installed all the basic setup of Android. We tried to run the Android Sample projects in Eclipse. But while to compile the following lines and a few other lines that uses the variable 'R' throws up an error.
setContentView(R.layout.activity_main);
'R cannot be resolved to a variable'. I do not understand what is causing the error. Anyone help me out in this issue.
check that the import for R class is not
import com.android.R;
and you should make it
import yourpackagename.R;
then recompile
Please try to clean the project, and try compiling again.
If not solved, refer to R cannot be resolved - Android error
If you have 64 bit Linux platform without ia32 libraries, then this problem could also occur. It took me quite some time to pin this one down, seeing that the problem is not clearly linked with the inability to execute 32 bit code.
Just make the import part import com.android.R.layout instead of com.android.R
In my case i forgot to re-install the SDK. When you re-install your operating system, you should re-extract (re-install) your SDK Zip file.
Also check that you have your android libraries mapped correctly in the settings for Eclipse (if you are using eclipse to develop).
Check if your resorce name (for example template.xml) has ONLY small caps letters.
import com.packagename.R* will worl
Change import to
import yourpackagename.R;
If error is still there then
go to gen folder->packagename->R.java
and remove error line some times it gave error on drawable files.
setContentView(R.layout.activity_main)
Change the SDK and delete the project and create new ... it will definitely work!

Categories

Resources