当我从一个活动组调用一个活动时,我得到了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>
答案 0 :(得分:3)
根据您的堆栈跟踪,您有一个巨大的嵌套视图层次结构,试图绘制自己。
要么它是一个疯狂的深层次结构,要么你可能以编程方式在ViewGroup
内构建\ inflate子视图,最终创建一个递归视图包含。
无论哪种方式,它似乎与您发布的代码无关,而是与有问题的活动的实际UI内容有关。
如果在活动布局中没有发现问题(从堆栈跟踪中看起来很明显),请在您的问题中发布布局XML或布局代码。