2

当我从活动组调用活动时,我得到 java.lang.StackOverflowError。

以下是代码:

Intent i = new Intent(PermissionsScreen.this,DownloadActivity.class);
replaceContentView("Activity10",i);
public void replaceContentView(String id, Intent newIntent) {
View view = getLocalActivityManager().startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) .getDecorView();
this.setContentView(view);
    }

当我调用不同的活动代替 DownloadActivity.class 时,我没有收到 java.lang.StackOverflowError,如图所示

Intent i = new Intent(PermissionsScreen.this,PaymentScreen.class);
replaceContentView("Activity10",i);

PaymentScreen 和DownloadActivity 的区别在于,PaymentScreen 是一个简单的活动。而 DownloadActivity 使用 asynctask 来下载文件。

是什么导致 StackOverflowError 在我启动一个活动时发生而在另一种情况下不发生?

我找不到任何明显的原因。

任何帮助表示赞赏。

05-15 12:38:11.906: WARN/audio_hw_primary(135): select_output_device e=0, h=0, s=2, b=0
05-15 12:38:11.953: INFO/dalvikvm(6119): threadid=1: stack overflow on call to Landroid/text/TextLine;.handleText:FLIIIIZLFIIILZ
05-15 12:38:11.953: INFO/dalvikvm(6119):   method requires 164+20+40=224 bytes, fp is 0x56c9b36c (108 left)
05-15 12:38:11.953: INFO/dalvikvm(6119):   expanding stack end (0x56c9b300 to 0x56c9b000)
05-15 12:38:11.953: INFO/dalvikvm(6119): Shrank stack (to 0x56c9b300, curFrame is 0x56c9b88c)
05-15 12:38:11.953: DEBUG/AndroidRuntime(6119): Shutting down VM
05-15 12:38:11.953: WARN/dalvikvm(6119): threadid=1: thread exiting with uncaught exception (group=0x40b1a1f8)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119): FATAL EXCEPTION: main
05-15 12:38:11.968: ERROR/AndroidRuntime(6119): java.lang.StackOverflowError
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.text.TextLine.handleRun(TextLine.java:1021)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.text.TextLine.measureRun(TextLine.java:470)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.text.TextLine.measure(TextLine.java:315)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.text.TextLine.metrics(TextLine.java:289)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.text.Layout.getLineExtent(Layout.java:949)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.text.Layout.draw(Layout.java:409)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.text.BoringLayout.draw(BoringLayout.java:400)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.widget.TextView.onDraw(TextView.java:5004)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.draw(View.java:10880)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10319)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10317)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10317)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10317)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.draw(View.java:10883)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.widget.FrameLayout.draw(FrameLayout.java:450)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.widget.ScrollView.draw(ScrollView.java:1655)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10319)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.draw(View.java:10883)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10319)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10317)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10317)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10317)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10317)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10317)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10317)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10317)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10317)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10317)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10317)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10317)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10317)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.draw(View.java:10883)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.widget.FrameLayout.draw(FrameLayout.java:450)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.View.getDisplayList(View.java:10319)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     at android.view.ViewGroup.drawChild(ViewGroup.java:2862)
05-15 12:38:11.968: ERROR/AndroidRuntime(6119):     
05-15 12:38:12.046: WARN/ActivityManager(261):   Force finishing activity com.nykkos.personalize/.profiler.Personalization
05-15 12:38:12.109: INFO/WindowManager(261): createSurface Window{424e87a0  paused=false}: DRAW NOW PENDING
05-15 12:38:12.117: DEBUG/dalvikvm(6119): GC_CONCURRENT freed 1265K, 8% free 17457K/18823K, paused 8ms+14ms

以下是活动的布局:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:id="@+id/bottom_layout_downloading"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/total_progress" />

    <ProgressBar
        android:id="@+id/all_download_downloading"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:indeterminateOnly="false"
        android:maxHeight="10dip"
        android:minHeight="10dip" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="10dp" >

        <Button
            android:id="@+id/exit_btn_downloading"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/exit_back" />

        <Button
            android:id="@+id/download_btn_downloading"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/start_download" />
    </LinearLayout>
</LinearLayout>

  </LinearLayout>
  </ScrollView>
  </RelativeLayout>

下面给出的是我在 DownloadActivity 中使用的适配器的布局

    <?xml version="1.0" encoding="utf-8"?>
 <TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textViewContent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/blue"
        android:textSize="22sp" />

    <TextView
        android:id="@+id/textLink"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="fill_parent"
        android:layout_height="12dp"
        android:progressDrawable="@drawable/green_progress_color" />

    <TextView
        android:id="@+id/textPercent"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:gravity="right"
        android:text="0%"
        android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>

</TableRow>
4

1 回答 1

3

根据您的堆栈跟踪,您有一个巨大的嵌套视图层次结构,它试图自行绘制。

要么它是一个非常深的层次结构,要么你以编程方式在你的内部构建\膨胀子视图ViewGroup,并最终创建一个递归视图包含。

无论哪种方式,它似乎都与您发布的代码无关,而是与有问题的活动的实际 UI 内容有关。

如果您在活动布局中没有发现问题(从堆栈跟踪中看起来很明显),请在您的问题中发布您的布局 XML 或布局代码。

于 2013-05-15T13:44:53.970 回答