Android application crashing with RuntimeException: Unable to instantiate activity, dident find class

StackOverflow https://stackoverflow.com/questions/21645754

  •  08-10-2022
  •  | 
  •  

Question

I am creating an android application and when ever i try to run it the application crashes immediately and i get the folowing error in the LogCat

02-08 23:36:55.846: E/AndroidRuntime(15192): FATAL EXCEPTION: main
02-08 23:36:55.846: E/AndroidRuntime(15192): Process: com.danielscode.cube, PID: 15192
02-08 23:36:55.846: E/AndroidRuntime(15192): java.lang.RuntimeException: Unable to     instantiate activity     ComponentInfo{com.danielscode.cube/com.danielscode.cube.CUBEMenuActivity}: java.lang.ClassNotFoundException: Didn't find class "com.danielscode.cube.CUBEMenuActivity" on path: DexPathList[[zip file "/data/app/com.danielscode.cube-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.danielscode.cube-2, /vendor/lib, /system/lib]]
02-08 23:36:55.846: E/AndroidRuntime(15192):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
02-08 23:36:55.846: E/AndroidRuntime(15192):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-08 23:36:55.846: E/AndroidRuntime(15192):    at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-08 23:36:55.846: E/AndroidRuntime(15192):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-08 23:36:55.846: E/AndroidRuntime(15192):    at android.os.Handler.dispatchMessage(Handler.java:102)
02-08 23:36:55.846: E/AndroidRuntime(15192):    at android.os.Looper.loop(Looper.java:136)
02-08 23:36:55.846: E/AndroidRuntime(15192):    at android.app.ActivityThread.main(ActivityThread.java:5017)
02-08 23:36:55.846: E/AndroidRuntime(15192):    at java.lang.reflect.Method.invokeNative(Native Method)
02-08 23:36:55.846: E/AndroidRuntime(15192):    at java.lang.reflect.Method.invoke(Method.java:515)
02-08 23:36:55.846: E/AndroidRuntime(15192):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-08 23:36:55.846: E/AndroidRuntime(15192):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-08 23:36:55.846: E/AndroidRuntime(15192):    at dalvik.system.NativeStart.main(Native Method)
02-08 23:36:55.846: E/AndroidRuntime(15192): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.danielscode.cube.CUBEMenuActivity" on path: DexPathList[[zip file "/data/app/com.danielscode.cube-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.danielscode.cube-2, /vendor/lib, /system/lib]]
02-08 23:36:55.846: E/AndroidRuntime(15192):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
02-08 23:36:55.846: E/AndroidRuntime(15192):    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
02-08 23:36:55.846: E/AndroidRuntime(15192):    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
02-08 23:36:55.846: E/AndroidRuntime(15192):    at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
02-08 23:36:55.846: E/AndroidRuntime(15192):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
02-08 23:36:55.846: E/AndroidRuntime(15192):    ... 11 more

My first thought was that i had spelled the class names in the manafest file but i have double and tripple checked thoughs and they are correct. The folowing is my manafest file

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.danielscode.cube"
    android:versionCode="1"
    android:versionName="0.1" >

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/cubeicon1"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <activity android:name=".CUBEMenuActivity">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>
        </activity>

        <activity android:name=".CUBEGameActivity"></activity>

    </application>
</manifest>

Has anyone else had a similar problem? any help fixing this would be much appreciated.

Was it helpful?

Solution

I think that your problem is that your class CubeMenuActivity is in a different package than com.danielscode.cube. If you see your manifest you have defined that package and not in your java class.

Remove the package from your AndroidManifest.xml or move your class to a package that meets the one declared in your manifest.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top