I have developed an application in which i have 4 tabs A,B,C,D. Each of the Tab contains an Activity. In the fourth tab D I have added an ActivityGroup in which I am having 3 more Activities X,Y,Z.In the fourth Tab where I have added the activity group I am getting StackOverflow error.Please help me out in fixing this error.
this is my stackTrace:--
07-15 15:22:45.587: ERROR/AndroidRuntime(222): Uncaught handler: thread main exiting due to uncaught exception
07-15 15:22:45.677: ERROR/AndroidRuntime(222): java.lang.StackOverflowError
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.widget.AbsListView.dispatchDraw(AbsListView.java:1324)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.widget.ListView.dispatchDraw(ListView.java:2972)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.View.draw(View.java:6641)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.widget.AbsListView.draw(AbsListView.java:2171)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.View.draw(View.java:6538)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.widget.FrameLayout.draw(FrameLayout.java:352)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.View.draw(View.java:6538)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.widget.FrameLayout.draw(FrameLayout.java:352)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.View.draw(View.java:6538)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.widget.FrameLayout.draw(FrameLayout.java:352)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.View.draw(View.java:6538)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.widget.FrameLayout.draw(FrameLayout.java:352)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.View.draw(View.java:6538)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.widget.FrameLayout.draw(FrameLayout.java:352)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.View.draw(View.java:6538)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.widget.FrameLayout.draw(FrameLayout.java:352)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
07-15 15:22:45开发者_如何学运维.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.View.draw(View.java:6538)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.widget.FrameLayout.draw(FrameLayout.java:352)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.view.View.draw(View.java:6538)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at android.widget.FrameLayout.draw(FrameLayout.java:352)
07-15 15:22:45.677: ERROR/AndroidRuntime(222): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow
Please help me out ...I am very new to android.
I suppose you have an infinite loop somewhere.
Probably you've added the same instance of a view twice somewhere in your hierarchy and now you've got a cycle.
Fix that. And fix your layout. I can't see a reason to have such a complex layout.
I have search all over the Google but couldn't find a solution. Then I have just came up with this idea and it works perfectly on my old Samsung Galaxy Nexus and the Vodafone VF695!
Here is my hack in the root FrameLayout of my very deep layout:
public class StackFrameLayout extends FrameLayout {
private boolean stackOverflow;
@Override
public void draw(final Canvas canvas) {
if (stackOverflow) {
stackDraw(canvas);
} else {
try {
super.draw(canvas);
} catch (StackOverflowError e) {
stackOverflow = true;
stackDraw(canvas);
}
}
}
public void stackDraw(final Canvas canvas) {
Thread thread = new Thread(getContext().getMainLooper().getThread().getThreadGroup(), new Runnable() {
@Override
public void run() {
StackFrameLayout.super.draw(canvas);
}
}, "draw-thread", 2000000);
thread.start();
try {
thread.join();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
So basically I passed the complicated drawing methods into a thread with larger stack size. So the stack of the methods called will stop increasing a that point. Then the UI thread wait for the drawing thread to finish its work and then continue to ensure it draw sequentially like running on the UI thread.
精彩评论