我遇到了与android对话框相关的堆栈溢出错误。我使用showDialog(DIALOG1)在哪个语句中包含大约21个对话框;当对话框和主活动包含在同一个类文件中时,显示效果很好的对话框,但是一旦我将对话框移动到另一个类文件并尝试从主活动访问它们,就会导致堆栈溢出错误。我尝试在对话框类中扩展Dialog类,以及扩展包含对话框的类(主要活动扩展classOfDialogs)。我似乎无法让对话框从另一个文件访问。有什么建议?任何帮助将不胜感激!谢谢!!
Stack Trace(或我可以收集的内容
)Thread [<1> main] (Suspended (exception StackOverflowError))
Looper.myLooper() line: 137
Handler.<init>() line: 119
AlphaAthensActivity(Activity).<init>() line: 679
AlphaAthensActivity(Dialogs).<init>() line: 13
AlphaAthensActivity.<init>() line: 55
AlphaAthensActivity(Dialogs).<init>() line: 36
AlphaAthensActivity.<init>() line: 55
AlphaAthensActivity(Dialogs).<init>() line: 36
AlphaAthensActivity.<init>() line: 55
Class.newInstanceImpl() line: not available [native method]
Class.newInstance() line: 1429
Instrumentation.newActivity(ClassLoader, String, Intent) line: 1021
ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2577
ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2679
ActivityThread.access$2300(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 125
ActivityThread$H.handleMessage(Message) line: 2033
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]
答案 0 :(得分:0)
看起来你正在递归地调用这个Activity的Dialog。
AlphaAthensActivity(Activity).<init>() line: 679
AlphaAthensActivity(Dialogs).<init>() line: 13
AlphaAthensActivity.<init>() line: 55
AlphaAthensActivity(Dialogs).<init>() line: 36
AlphaAthensActivity.<init>() line: 55
AlphaAthensActivity(Dialogs).<init>() line: 36
AlphaAthensActivity.<init>() line: 55
为避免应用程序内存不足,抛出此异常。我认为你需要重新设计你的代码。更好的想法是将Dialogs放在一个公共基类中并扩展它。