间接延长活动

时间:2009-10-08 09:51:04

标签: java android android-activity

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

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

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

有没有办法做到这一点?目前以上述形式给我一个没有找到例外的课程。

Logcat:

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

时,不会发生错误

1 个答案:

答案 0 :(得分:1)

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

与依赖关系没有任何关系,在超类的代码中有一个未被捕获的异常打破了它。