Android应用程序因RuntimeException崩溃:无法实例化活动,dident找到类

时间:2014-02-08 12:03:02

标签: java android runtimeexception

我正在创建一个Android应用程序,当我尝试运行它时,应用程序立即崩溃,我在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

我的第一个想法是,我在manafest文件中拼写了类名,但是我检查了双重和三重奏并且它们是正确的。以下是我最安全的文件

<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>

还有其他人有过类似的问题吗?任何帮助解决这个问题将非常感激。

1 个答案:

答案 0 :(得分:0)

我认为您的问题是您的班级CubeMenuActivity与其他人不同 com.danielscode.cube。如果你看到你的清单你已经定义了那个包而不是你的java类。

AndroidManifest.xml中移除包裹,或将您的班级移至符合清单中声明的​​包裹。