2011-10-24 51 views
0

我遇到了與android對話框有關的堆棧溢出錯誤。我使用showDialog(DIALOG1)在一個語句中包含了大約21個對話框。當對話框和主要活動都包含在同一個類文件中時,顯示對話框效果很好,但是一旦我將對話框移動到另一個類文件並嘗試從主活動訪問它們,就會導致堆棧溢出錯誤。我試過在對話框類中擴展Dialog類以及擴展包含對話框的類(主要活動擴展了classOfDialogs)。我似乎無法讓對話從另一個文件訪問。有什麼建議麼?任何幫助將不勝感激!謝謝!!Android對話框通過單獨的類存儲和訪問

堆棧跟蹤(或者是我可以收集

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

發佈你的棧跟蹤。 – FoamyGuy

+0

我的道歉我新來堆棧溢出 –

回答

0

它看起來像你遞歸調用該活動的對話框。

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 

爲了避免運行內存的應用程序,這將引發異常。我認爲你需要重新設計你的代碼。一個更好的主意是將對話框放在一個共同的基類中並且擴展它。

+0

看到多數民衆贊成我現在有,如果我將對話框包括到主要活動類一切工作正常,但秒移動他們到一個共同的基類和擴展它我得到這個堆棧溢出 –