2

为了便于使用,我想用某个类扩展一个 Android Activity 以赋予它额外的功能,然后用那个类扩展我的主要活动,例如

class SuperActivity extends Activity {
    //Very nice extra functions
}

//Class defined in the manifest.xml
class ApplicationActivity extends SuperActivity {
    //Start the application
}

有什么办法吗?目前在上面的表格中,它给了我一个找不到类的异常..

日志猫:

10-08 12:23:28.316: ERROR/AndroidRuntime(678): Uncaught handler: thread main exiting due to uncaught exception
10-08 12:23:28.336: ERROR/AndroidRuntime(678): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{ntx.app/ntx.app.AppActivity}: java.lang.ClassNotFoundException: ntx.app.AppActivity in loader dalvik.system.PathClassLoader@437601e8
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324)
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     at android.app.ActivityThread.access$2100(ActivityThread.java:116)
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     at android.os.Looper.loop(Looper.java:123)
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     at android.app.ActivityThread.main(ActivityThread.java:4203)
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     at java.lang.reflect.Method.invokeNative(Native Method)
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     at java.lang.reflect.Method.invoke(Method.java:521)
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     at dalvik.system.NativeStart.main(Native Method)
10-08 12:23:28.336: ERROR/AndroidRuntime(678): Caused by: java.lang.ClassNotFoundException: ntx.app.AppActivity in loader dalvik.system.PathClassLoader@437601e8
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     at android.app.Instrumentation.newActivity(Instrumentation.java:1097)
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2316)
10-08 12:23:28.336: ERROR/AndroidRuntime(678):     ... 11 more

当我让 AppActivity 扩展 android.app.Activity 时不会发生错误

4

1 回答 1

1

解决了这个问题,我添加了一个项目依赖项,但我应该直接添加 .jar 文件。

与依赖无关,超类的代码中有一个未捕获的异常破坏了它。

于 2009-10-08T11:12:14.833 回答