java – AndEngine – 无法实例化Activity

前端之家收集整理的这篇文章主要介绍了java – AndEngine – 无法实例化Activity前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是 Android开发的新手,在使用AndEngine时遇到了问题.我试图运行一个空的应用程序,但得到一个运行时错误,如下所示:
04-01 21:56:16.326: W/dalvikvm(280): Unable to resolve superclass of Lcom/MyApps/TestApp/TestAppActivity; (31)
04-01 21:56:16.326: W/dalvikvm(280): Link of class 'Lcom/MyApps/TestApp/TestAppActivity;' Failed
04-01 21:56:16.336: D/AndroidRuntime(280): Shutting down VM
04-01 21:56:16.336: W/dalvikvm(280): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-01 21:56:16.376: E/AndroidRuntime(280): FATAL EXCEPTION: main
04-01 21:56:16.376: E/AndroidRuntime(280): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.MyApps.TestApp/com.MyApps.TestApp.TestAppActivity}: java.lang.ClassNotFoundException: com.MyApps.TestApp.TestAppActivity in loader dalvik.system.PathClassLoader[/data/app/com.MyApps.TestApp-1.apk]
04-01 21:56:16.376: E/AndroidRuntime(280):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
04-01 21:56:16.376: E/AndroidRuntime(280):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-01 21:56:16.376: E/AndroidRuntime(280):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-01 21:56:16.376: E/AndroidRuntime(280):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-01 21:56:16.376: E/AndroidRuntime(280):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 21:56:16.376: E/AndroidRuntime(280):  at android.os.Looper.loop(Looper.java:123)
04-01 21:56:16.376: E/AndroidRuntime(280):  at android.app.ActivityThread.main(ActivityThread.java:4627)
04-01 21:56:16.376: E/AndroidRuntime(280):  at java.lang.reflect.Method.invokeNative(Native Method)
04-01 21:56:16.376: E/AndroidRuntime(280):  at java.lang.reflect.Method.invoke(Method.java:521)
04-01 21:56:16.376: E/AndroidRuntime(280):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-01 21:56:16.376: E/AndroidRuntime(280):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-01 21:56:16.376: E/AndroidRuntime(280):  at dalvik.system.NativeStart.main(Native Method)
04-01 21:56:16.376: E/AndroidRuntime(280): Caused by: java.lang.ClassNotFoundException: com.MyApps.TestApp.TestAppActivity in loader dalvik.system.PathClassLoader[/data/app/com.MyApps.TestApp-1.apk]
04-01 21:56:16.376: E/AndroidRuntime(280):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-01 21:56:16.376: E/AndroidRuntime(280):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-01 21:56:16.376: E/AndroidRuntime(280):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-01 21:56:16.376: E/AndroidRuntime(280):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-01 21:56:16.376: E/AndroidRuntime(280):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
04-01 21:56:16.376: E/AndroidRuntime(280):  ... 11 more

使用过的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.MyApps.TestApp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".TestAppActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

我尝试将整个包名称替换为.TestAppActivity,但没有任何运气.
但是,当我从Activity而不是BaseGameActivity扩展TestAppActivity时,它起作用了.

任何帮助表示赞赏,
萨米

解决方法

错误无法解析Lcom / MyApps / TestApp / TestAppActivity的超类,并且当您从Activity继承时它会起作用,这表明您没有在APK中包含AndEngine库 – 因此在运行时无法找到BaseGameActivity.

确保AndEngine依赖项位于Android项目的libs目录中;不只是添加到Eclipse类路径中.

事实上,如果你有最新的Android Eclipse插件,如果只是将它们放在libs中,任何依赖项都会自动包含在你的APK中.

猜你在找的Java相关文章