I am experiencing an error quite often among my users. The app crashes during startup. When the MainActivity is supposed to be loaded the VM apparently cannot find the class
Try go to
I hope it helps.
I encountered this NoClassDefFoundError when I used java.nio.charset.StandardCharsets.
The reason is that StandardCharsets has not existed until JRE 1.7. If I make the java compile version set to 1.7, Eclipse complained that "Android requires compiler compliance level 5.0 or 6.0". So, I fixed it by right-click the project name->Android Tools->Fix Project Properties. It is compiled with JRE1.6.
However, because StandardCharsets has not existed until 1.7. It reported NoClassDefFoundError when I ran it.
I has not come to realize this until after trying a lot of other methods including reinstalling JDK. The real reason is clearly told by the meaning of NoClassDefFoundError: The class cannot be found at run time although it passed compilation.
General conclusion is that as long as Android does not work with JRE 1.7, if you use any new feature provided since 1.7, you will encounter this error.
My solution is that I copied those source code into my code!
This error is also generated when you make an app that uses the Google API (such as Maps) but run it on a device that targets the Android API.
I had the same issue, I did the following to fix the problem.
gen - automated code in project (from dependencies and references)
src - source code in project
There was no need to restart the Eclipse. It just started working.
Honestly I have never tried "Android Tools > Fix Project Properties", sometimes it might be doing the same thing. I do not know, I just did above after seen the error message, thinking something is wrong with the build paths.
Edit
Later on it was not sufficient, I was getting the error again. Then I "checked" all the dependencies listed in that view. Now it works again. So far so good. I will keep this updated if it fails again.
FYI: in my last attempt, I tried "Android Tools > Fix Project Properties", but it didn't work out for me.
I am guessing that you don't specify javac
's target when creating the common library, so javac
automatically uses the latest available target, which is likely 1.7 (Java7) or 1.8 (Java8).
It has already been stated that
Android requires compiler compliance level 5.0 or 6.0
dx
of Android's build tools < 19.0.0 isn't able to convert Java7 (or higher) bytecode to Dalvik bytecode.
So either use a build tools version >= 19.0.0 or use javac
with -target 6, by modifying for example your ant build.xml
like this:
<javac
srcdir="src/"
destdir="build/"
target="6"
/>
Try going to Project -> Properties -> Java Build Path -> Order & Export and ensure Android Private Libraries are checked for your project and for all other library projects you are using. i got the solution by following below link NoClassDefFoundError Android Project?