我在 android 中有一个简单的活动程序。基本上这个类只是扩展了 Activity。但是当我启动它时,我在我的类的构造函数中得到一个 ClassCastException 。我什至没有定义构造函数,所以它必须在超类的构造函数中,即 Activity。
不幸的是,调试器没有提供任何关于它试图强制转换的类的详细信息。
这是堆栈跟踪:
Thread [<1> main] (Suspended (exception RuntimeException))
ActivityThread$PackageInfo.makeApplication(boolean, Instrumentation) line: 649
ActivityThread.handleBindApplication(ActivityThread$AppBindData) line: 4232
ActivityThread.access$3000(ActivityThread, ActivityThread$AppBindData) line: 125
ActivityThread$H.handleMessage(Message) line: 2071
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4627
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 868
ZygoteInit.main(String[]) line: 626
NativeStart.main(String[]) line: not available [native method]
当我查看运行时异常时,我得到:
detailMessage "Unable to instantiate application com.test.MyApp: java.lang.ClassCastException: com.test.MyApp" (id=830067694464)
唯一的代码是
package com.test;
import android.app.Activity;
public class MyApp extends Activity {
}