Fragments中的StackOverflow异常

时间:2012-11-14 17:26:40

标签: android

我有一个包含5个标签的tabhost FragmentActivity。其中一个包含7个视图的序列。我认为每个都是片段,但当我到片段7时,应用程序会爆炸。

enter image description here

enter image description here

当我按下每个片段中的继续按钮时,我会以这种方式开始一个新片段:

   MyFragment newFragment = new MyFragment ();
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.publish_map_direction, newFragment);
    transaction.addToBackStack(null);
    transaction.commit();

这是错误:

11-14 13:50:33.640: I/dalvikvm(13823): threadid=1: stack overflow on call to Landroid/text/Layout;.draw:VLLLI
11-14 13:50:33.640: I/dalvikvm(13823):   method requires 288+20+60=368 bytes, fp is 0x4428a42c (300 left)
11-14 13:50:33.640: I/dalvikvm(13823):   expanding stack end (0x4428a300 to 0x4428a000)
11-14 13:50:33.640: I/dalvikvm(13823): Shrank stack (to 0x4428a300, curFrame is 0x4428cc74)
11-14 13:50:33.640: D/AndroidRuntime(13823): Shutting down VM
11-14 13:50:33.640: W/dalvikvm(13823): threadid=1: thread exiting with uncaught exception (group=0x40015578)
11-14 13:50:33.703: E/AndroidRuntime(13823): FATAL EXCEPTION: main
11-14 13:50:33.703: E/AndroidRuntime(13823): java.lang.StackOverflowError
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.widget.TextView.onDraw(TextView.java:4229)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.View.draw(View.java:6933)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.View.draw(View.java:6936)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.View.draw(View.java:6936)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.View.buildDrawingCache(View.java:6695)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.onAnimationStart(ViewGroup.java:1259)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1505)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.View.draw(View.java:6936)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.View.draw(View.java:6936)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.View.draw(View.java:6936)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.View.draw(View.java:6936)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.View.draw(View.java:6936)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.View.draw(View.java:6936)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.widget.FrameLayout.draw(FrameLayout.java:357)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.View.draw(View.java:6936)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.View.draw(View.java:6936)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.widget.FrameLayout.draw(FrameLayout.java:357)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.View.draw(View.java:6936)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.widget.FrameLayout.draw(FrameLayout.java:357)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.View.draw(View.java:6936)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.widget.FrameLayout.draw(FrameLayout.java:357)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1904)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewRoot.draw(ViewRoot.java:1527)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewRoot.performTraversals(ViewRoot.java:1263)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.os.Looper.loop(Looper.java:130)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at android.app.ActivityThread.main(ActivityThread.java:3687)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at java.lang.reflect.Method.invokeNative(Native Method)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at java.lang.reflect.Method.invoke(Method.java:507)
11-14 13:50:33.703: E/AndroidRuntime(13823):    at com.

我应该以不同的方式构建我的应用程序吗?

1 个答案:

答案 0 :(得分:1)

我建议只使用片段,而不是在标签主机中嵌套片段活动。我通常会创建一个标签栏,并在其下方放置一个框架,我将一个片段放入其中。然后我根据点击的内容替换片段。这肯定会有所帮助,因为我认为你们有太多事情要同时进行。