Android 对话框通过单独的类存储和访问
我遇到了与 Android 对话框相关的堆栈溢出错误。我使用 showDialog(DIALOG1); 的哪个语句中包含大约 21 个对话框。当对话框和主活动都包含在同一个类文件中时,显示对话框效果很好,但是一旦我将对话框移动到另一个类文件中并尝试从主活动访问它们,就会导致堆栈溢出错误。我尝试扩展对话框类中的 Dialog 类以及扩展包含对话框的类(主要活动扩展 classOfDialogs)。我似乎无法让对话框从另一个文件访问。有什么建议吗?任何帮助将不胜感激!谢谢!!
堆栈跟踪(或者我能收集到的
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]
I'm having a stack overflow error relating to android dialogs. I have around 21 dialogs contained within a which statement using showDialog(DIALOG1); to display the dialogs which works great when both the dialogs and the main activity are contained within the same class file but once I move the dialogs into another class file and try to access them from the main activity it causes a stack overflow error. I've tried extending the Dialog class in the dialog class as well as extending the class that contains the dialogs(main activity extends classOfDialogs). I can not seem to get the dialogs to work being accessed from another file. Any suggestions? Any help would be greatly appreciated! Thanks!!
Stack Trace (or what I could gather
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]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您正在递归调用此活动的对话框。
为了避免应用程序内存不足,抛出此异常。我认为你需要重新设计你的代码。更好的想法是将对话框放在一个公共基类中并扩展它。
It looks like you are calling this Activity's Dialog recursively.
To avoid the application running out of memory, this exception is thrown. I think you need to redesign your code. A better idea will be to have the Dialogs in a common base class and extend it.