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...!
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 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
The NoClassDefFoundError description is, from the SO tag:
Or better:
from this page. Check it, there are some ways to solve the error. I hope it helps.
I am guessing that you don't specify
javac
's target when creating the common library, sojavac
automatically uses the latest available target, which is likely 1.7 (Java7) or 1.8 (Java8).It has already been stated that
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 antbuild.xml
like this: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.
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.