java.lang.RuntimeException: Unable to instantiate activity ComponentInfo / java.lang.ClassNotFoundException
Asked Answered
R

5

7

I'm having this error while running on my device. I've been browsing the issue and I'm pretty sure I'm not having the same issues as mentioned. Both of my activities are declared in the AndroidManifest and the intent filter is there. I have no libraries whatsoever (except v4 support library, but declaring it doesn't change the problem). I tried replacing in my Manifest carpedujourproductions.quickpronote.MainActivity by .MainActivity but still no luck. I'm running Android Studio 0.2.5 so I couldn't find how to resolve potential issues related to Java Build Path/Order and Export

I couldn't help but noticing my MainActivity's icon in the tree had a grey cross on the upper-left corner.

Logcat:

E/AndroidRuntime: FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{carpedujourproductions.quickpronote/carpedujourproductions.quickpronote.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "carpedujourproductions.quickpronote.MainActivity" on path: DexPathList[[zip file "/data/app/carpedujourproductions.quickpronote-2.apk"],nativeLibraryDirectories=[/data/app-lib/carpedujourproductions.quickpronote-2, /vendor/lib, /system/lib]]
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2157)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2281)
        at android.app.ActivityThread.access$600(ActivityThread.java:148)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1263)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5124)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:525)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:110)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: java.lang.ClassNotFoundException: Didn't find class "carpedujourproductions.quickpronote.MainActivity" on path: DexPathList[[zip file "/data/app/carpedujourproductions.quickpronote-2.apk"],nativeLibraryDirectories=[/data/app-lib/carpedujourproductions.quickpronote-2, /vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
        ... 12 more

Feel free to browse through the code here for AndroidManifest, MainActivity.java, FirstRun.java, etc.

Rolan answered 30/8, 2013 at 12:34 Comment(1)
It could be an Eclipse build problem when refreshing the project files. See here for a possible solution.Kiefer
A
3

Your MainActivity.java is excluded from compile, so this class isn't included in .apk. Remove line:

<file url="file://$PROJECT_DIR$/src/carpedujourproductions/quickpronote/MainActivity.java" />

from the excludeFromCompile section of the .idea/compiler.xml file (or you can do this from IDE settings).

Annihilation answered 30/8, 2013 at 12:41 Comment(1)
Thanks! I have other (minor) errors now, but you saved me on this one!Rolan
T
2

This error could be raised with several causes, for my experience i expose two of them.

  • if we have some code lines in resource files that are inserted by SVN Client like smartSVN or tortoise.

    <<<<<<< .mine
        <string name="pathConfiguration">http://jorgesys/app/config_development.xml</string>
    =======    
    
    >>>>>>> .r124
    

    <<<<<<< .mine

    removing that characters:

    <string name="pathConfiguration">http://jorgesys/app/config_development.xml</string>
    
  • Into the .classpath file add the line

    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
    

this is an example:

  <?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
    <classpathentry kind="src" path="gen"/>
    <classpathentry kind="output" path="bin/classes"/>
</classpath>

Now it works! =)

it will fix the exception

Till answered 30/1, 2014 at 18:24 Comment(0)
S
2

I had the same problem. Cleaning the project should do the trick

Slating answered 5/4, 2014 at 23:40 Comment(0)
L
1

If you add additional libs to your project you need to export them with your project in case that some classes excluded.

right click your project and go to Properties. Click Java Build Path on left panel and navigate to Order and Export tab. You may need to check the third party libs in order to add them to build path and export them to apk. Also notice that the order of libs are also important, the topper they are the higher properties they have when building apk.

Longways answered 5/9, 2014 at 9:20 Comment(0)
S
1

I just changed

compileOptions{
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

to

compileOptions{
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

and it worked like a charm.....

Sarre answered 5/9, 2014 at 10:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.