2017-03-05 6 views
2

このコードは私にjava.lang.StackOverflowError: stack size 8MBエラー、何らかの理由がありますか?私はNestedScrollViewの内部にTableLayoutとTableRowを持っています。 java.lang.StackOverflowError:スタックサイズ8MBのビュー

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="eu.martinbednar.mayak.TripList" 
    tools:showIn="@layout/activity_scrolling" 
    android:id="@+id/table"> 

    <TableLayout 
     android:id="@+id/tableLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="10dip" 
     android:isScrollContainer="true"> 
    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
    </TableRow> 
    </TableLayout> 


</android.support.v4.widget.NestedScrollView> 

が助けてくれてありがとう:

String testString = "test"; 
tableLayout = (TableLayout) findViewById(R.id.tableLayout1); 
TextView textInRow = new TextView(this) 
TableRow tableRow = new TableRow(this); 
textInRow.setText(testString); 
tableRow.addView(tableRow); 
tableLayout.addView(tableRow); 

は、ここで私の活動のxmlファイルです。

答えて

5

言うのは難しいが、私はこの

tableRow.addView(tableRow); 

が原因である可能性がありますね。それ自体にビューを追加すると、それがStackOverflowError

+0

ありがとうございます、私は気づいていません... –

0
String testString = "test"; 
    tableLayout = (TableLayout) findViewById(R.id.tableLayout1); 
    TextView textInRow = new TextView(this) 
    TableRow tableRow = new TableRow(this); 
    textInRow.setText(testString); 
    tableRow.addView(textInRow); 
    tableLayout.addView(tableRow); 

が代わりにこれを使用し、したがって、無限再帰の原因と考えられます。

関連する問題