Take the 2-minute tour ×

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. I cannot figure out why. The architecture of the app is that there is a common project that both my free and pro version are using. Don't know if it is relevant. See the stack trace below. Any thoughts?

java.lang.NoClassDefFoundError: com.android.common.MainActivity
at com.mycompany.myapp.Splash.onCreate(Splash.java:23)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.android.common.MainActivity in loader     dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.android.pro-1.apk]

Edit: Thanks for the comment below, Richard. Now I have changed com.android.Splash to something else. It wasn't the real classname anyway. My bad...!

share|improve this question
Why would you ever try to create a class in a package that already exists? (com.android.*). That's bad form, try changing the package around. –  Richard J. Ross III Oct 30 '12 at 17:25
Does this only happen some of the times? or does it happen all the time when you build locally? –  David T. Aug 28 '13 at 21:50
It happened only for the app launched to Play. Haven't seen it myself, so I have just seen the stack trace retrieved on Crittercism. –  kjoelbro Aug 29 '13 at 11:49
add comment

20 Answers

up vote 79 down vote accepted

I had the same issue, I did the following to fix the problem.

  1. Go to "Properties" of the project.
  2. Select "Java Build Path"
  3. Select "Order and Export" Tab
  4. You should see the selected project's "src" and "gen" paths and dependencies here.
  5. The order how they listed were first "src" and then "gen" path
  6. I switch them, so that "gen" folder is build before the "src"

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.


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.

share|improve this answer
Your edited answer worked for me. Thanks. –  Andrew Mar 25 '13 at 11:01
Your answer worked well for me.. thanks.. –  RathaKrishna May 21 '13 at 6:19
wow, it's amazing that just switch the order of gen and src... –  Weibo Jun 7 '13 at 6:39
your edited ans worked for me as well...been pulling my hair for 2-3 hrs due to ClassDefNotFoundError –  Prativa Jun 25 '13 at 9:39
I am leaving a comment that someone may find one day. My problem was referencing a class from a library project that should not have been used. I found the error/solution in the "Libraries" tab instead. I don't know if it will ever help anyone, but now its on the internet. –  Andreas Rudolph Oct 14 '13 at 14:01
show 1 more comment

I'm currently using SDK 20.0.3 and none of the previous solutions worked for me.

I was able to get things to work by

  • Right clicking the Android project
  • Then selecting Build Path -> Link Source to bring up the Link Source dialog.
  • Then I specified the 'src' folder of the Java project and gave it a name other than the default of 'src' (e.g. 'src2').
  • You can now right-click -> delete the new 'src2' folder.

This brought this created Java class files that were compiled for the Dalvik VM instead of the Java VM when the Android project was built. This allowed the Java class files in the Android Library jar file to go thru dexing when the Android project .apk was created. Now when the app was run the Java project classes were found instead of a Java.lang.NoClassDefFoundError being thrown.

If you want to use a jar file instead of linking the source, then you will need to create a Library Android project. (An Android Project with 'is library' checked in Properties -> Android.) You will then need to either link the source of the Java Project to the Android Library project as described above or copy the source files from the 'src' folder of the Java Project to the 'src' folder of the Android Library project. Build the Android Library project. Then you will be able copy the Android Project jar file that was created into the 'libs' folder of the Android folder because the class files in it were compiled for the Davlik VM instead of the Java VM when the Android project was built. This allows the Java class files in the Android Library jar file to go thru dexing when the Android project .apk is created. Now when the app is run the Java project classes will be found instead of a Java.lang.NoClassDefFoundError being thrown.

share|improve this answer
add comment

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?

share|improve this answer
This worked for me!!! –  Ahamed Jun 25 '13 at 23:34
add comment

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.

share|improve this answer
this finally fixed my problem. somehow the fix project properties function doesn't change the target. i fixed this by updating my google api –  boreas Jun 21 '13 at 16:42
add comment

I tried all of the above said solutions but did not worked out for me, Here is what i did to get it done project-> config build path-> order and export-> move dependent project on top

share|improve this answer
add comment

Just in case it helps someone, I faced the same issue. My jar file was under the libs directory and the jar was added to the build path. Still it was throwing that exception.

I just cleaned the project and it worked for me.

Eclipse -> Project -> Clean -> Select the project and clean

share|improve this answer
This solved my problem. Cheers! –  Kong Ken Jul 4 '13 at 3:40
add comment

For me this problem was related to the API that I was using not being deployed. For example, I used a ZSDK_API.jar as a reference.

To fix the issue I had to right click on the project and select properties. From JAVA BUILD PATH, I had to add the API that was not being deployed. This was weird as the app was throwing MainActivity class not found and in reality the error was caused by the DiscoveryHandler class not being found.

Hopes this helps someone.

share|improve this answer
add comment

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!

share|improve this answer
+1 I tried using a .jar file that I had compiled with Java 1.7. After recompiling the jar with Java 1.6, it worked fine. –  Simon André Forsberg Jul 14 '13 at 11:46
add comment

The NoClassDefFoundError description is, from the SO tag:

The Java Error thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found. The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.

Or better:

NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available during compile time.

from this page. Check it, there are some ways to solve the error. I hope it helps.

share|improve this answer
Thank you Alberto! Your post helped me to understand the problem. Now I am curious about how Android is handling the classpath. Currently reading this issue: stackoverflow.com/questions/1095322/… –  kjoelbro Jan 2 '12 at 10:33
@Kjoendo You are welcome. I will read the link about the issue. :) –  Alberto Solano Jan 3 '12 at 11:53
I've just had this for a ConcurrentSkipListMap; I think it's because my application was run on a Froyo device, and that class is absent in Froyo; however, AdMob requires me to target Ice Cream Sandwich so I hadn't noticed this! –  Andrew Wyld Apr 10 '12 at 22:18
add comment

I have just figured out something with this error.

Just make sure that the library jar file contains the compiled R class under android.support.v7.appcompat package and copy all the res in the v7 appcompat support "project" in your ANDROID_SDK_HOME/extras/android/support/v7/appcompat folder.

I use Netbeans with the Android plugin and this solved my issue.

share|improve this answer
add comment

In my case, I was trying to add a normal java class (from a normal java project) compiled with jre 1.7 to an android app project compiled with jre 1.7.

The solution was to recompile that normal java class with jre 1.6 and add references to the android app project (compiled with jre 1.6 also) as usual (in tab order and export be sure to check the class, project, etc).

The same process, when using an android library to reference external normal java classes.

Don't know what's wrong with jre 1.7, when compiling normal java classes from a normal java project and try to reference them in android app or android library projects.

If you don't use normal java classes (from a normal java project) you don't need to downgrade to jre 1.6.

share|improve this answer
add comment

I fixed this issue by adding library project path in project.propertied manually. some how eclipse did not added this entry automaticvally along with "add project". so the point where app was trying to refer any componenrt inside lib project it was crashing .

you also can try the same thing . app dependecy in projec.properties like


and run .

share|improve this answer
add comment

Other idea. For example, you have class derived from "android.support.v4.app.Fragment".

However you made a mistake and inherited it from "android.app.Fragment". Then you will have this error on the Android 2 devices.

share|improve this answer
add comment

In my case I got this error because I hadn't added my library to the project. Following the info here (which was really just a refresher!) fixed it:

Adding Android library project to Eclipse build path?

share|improve this answer
add comment

jars used to be in the lib/ folder, now they're in libs/ If you use lib, you can move your jars from lib to libs, and remove the dependencies from project properties/java build path because Android will now find them automatically.

share|improve this answer
add comment

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:

share|improve this answer
add comment

For me, the issue was that the referenced library was built using java 7. I solved this by rebuilding using the 1.6 JDK.

share|improve this answer
add comment

Some time java.lang.NoClassDefFoundError: error appear when use ART instead of Dalvik runtime. To change runtime just go to Developer Option -> Select Runtime -> Dalvik.

share|improve this answer
add comment

If none of the above works (like it happened to me), and you're using as a library another project in Eclipse.

Do so: Right click project -> Properties -> Android -> Library -> Add

That did it for me! Adding a project as a library (Project Properties)

share|improve this answer
add comment

1)In Manifest file mention your activity name and action for it and also category . 2)In your Activity mention your starting contentview and mention your view id's in the activity.

share|improve this answer
add comment

Your Answer


