我如何解决Android应用程序的StackOverflowError?

时间:2013-02-05 13:31:40

标签: java android

** 我是一个新的Android开发者。我使用Android屏幕的布局... lauout设计是**

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

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/row1"
android:orientation="horizontal" >

<TableRow
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight=".1" >
</TableRow>

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight=".5"
android:orientation="vertical" >

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight=".2" >
</TableRow>

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/man" />
</TableRow>

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight=".2" >
</TableRow>

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/man" />
</TableRow>

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight=".2" >
</TableRow>
</LinearLayout>

<TableRow
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight=".1" >
</TableRow>

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="3"
android:orientation="vertical" >

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="BRUCE LEE $ MAO ZEDONG"
android:textColor="#000"
android:textSize="12sp"
android:textStyle="bold" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="25dp"
android:src="@drawable/clock" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="30 minute ago "
android:textColor="#000"
android:textSize="10sp"
android:textStyle="bold" />
</TableRow>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="3"
android:background="@drawable/backimage"
android:orientation="vertical" >

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight=".5" >
</TableRow>

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="4" >

<TableRow
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight=".2" >
</TableRow>

<TableRow
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/defaultbi" />
</TableRow>

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="3"
android:orientation="vertical" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LOREM IPSUM DOLOR SPECIAL OFFER 30%"
android:textColor="#000"
android:textSize="8sp"
android:textStyle="bold" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="prosato vai is a software enginure jhjdshjhjkfhjkfjksdjjdjjjkjiddsdj"
android:textColor="#fff"
android:textSize="8sp"
android:textStyle="bold" />
</LinearLayout>

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight=".4"
android:orientation="vertical" >

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight=".5" >
</TableRow>

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="2" >

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/arrow" />
</TableRow>

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight=".5" >
</TableRow>
</LinearLayout>
</TableRow>

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight=".8" >
</TableRow>
</LinearLayout>

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/pin" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="245 milles 22mb Baker Street London"
android:textColor="#000"
android:textSize="8sp"
android:textStyle="bold" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/cro" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="at Scroll Bar"
android:textColor="#000"
android:textSize="8sp"
android:textStyle="bold" />
</TableRow>
</LinearLayout>

<TableRow
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight=".1" >
</TableRow>
</LinearLayout>

<TableRow
android:layout_width="fill_parent"
android:layout_height="1dp" >

<View
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#a3a3a3" />
</TableRow>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/row1"
android:orientation="horizontal" >

<TableRow
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight=".1" >
</TableRow>

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight=".8"
android:orientation="vertical" >

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight=".8" >
</TableRow>

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.2" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/man" />
</TableRow>

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight=".8" >
</TableRow>
</LinearLayout>

<TableRow
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight=".1" >
</TableRow>

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="4"
android:orientation="vertical" >

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="JACKIE CHAN"
android:textColor="#000"
android:textSize="12sp"
android:textStyle="bold" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="45dp"
android:src="@drawable/photo" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:text="photo "
android:textColor="#000"
android:textSize="10sp"
android:textStyle="bold" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/clock" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:text="40 minute ago"
android:textColor="#000"
android:textSize="10sp"
android:textStyle="bold" />
</TableRow>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="3"
android:orientation="vertical" >

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="4" >

<TableRow
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="2.5" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fghghjdjdjfhdjfhjhjjjn  jhjhdfjds hjhdfjdnf " />
</TableRow>

<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >
</TableRow>

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/threetwo"
    android:text="Agree"
    android:textColor="#ffffff"
    android:textSize="14sp"
    android:textStyle="bold" />
</TableRow>


</LinearLayout>
</TableRow>
</LinearLayout>

<TableRow
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/pin" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="245 milles 22mb Baker Street London"
android:textColor="#000"
android:textSize="8sp"
android:textStyle="bold" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/cro" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="at Scroll Bar"
android:textColor="#000"
android:textSize="8sp"
android:textStyle="bold" />
</TableRow>
</LinearLayout>

<TableRow
android:layout_width="0dip"`enter code here`
android:layout_height="fill_parent"
android:layout_weight=".2" >
</TableRow>
</LinearLayout>

</LinearLayout>

但是当我运行我的应用程序时,它会显示StackOverflowError.those错误显示到logcat .....

    FATAL EXCEPTION: main
    java.lang.StackOverflowError
at android.view.View.draw(View.java:6739)
at android.view.ViewGroup.drawChild(ViewGroup.java:1648)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)`enter code here`
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.ja`enter code here`va:1375)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.View.draw(View.java:6742)
at android.view.ViewGroup.drawChild(ViewGroup.java:1648)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.View.draw(View.java:6742)
at android.view.ViewGroup.drawChild(ViewGroup.java:1648)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.widget.AbsListView.dispatchDraw(AbsListView.java:1365)
at android.widget.ListView.dispatchDraw(ListView.java:3046)
at android.view.View.draw(View.java:6845)
at android.widget.AbsListView.draw(AbsListView.java:2257)
at android.view.View.buildDrawingCache(View.java:6501)
at android.view.View.getDrawingCache(View.java:6287)
at android.view.ViewGroup.drawChild(ViewGroup.java:1573)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.View.draw(View.java:6742)
at android.support.v4.view.ViewPager.draw(ViewPager.java:1923)
at android.view.ViewGroup.drawChild(ViewGroup.java:1648)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.View.draw(View.java:6742)
at android.view.ViewGroup.drawChild(ViewGroup.java:1648)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.View.draw(View.java:6742)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1648)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.View.draw(View.java:6742)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1648)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.View.draw(View.java:6742)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1648)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.View.draw(View.java:6742)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1648)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.View.draw(View.java:6742)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at    com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1872)
at android.view.View`enter code here`Root.draw(ViewRoot.java:1422)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1167)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1744)

现在,我怎么能解决这个错误请帮帮我..(我用htc 2.2 os设备)

2 个答案:

答案 0 :(得分:1)

首先,您必须重新定义您的布局。您正在使用TableRowTableRow应始终用作TableLayout的子级。

我建议您阅读有关在Android中设计正确布局的文档。 TableLayout/TableRow的用途很少(但很多人滥用它们,就像在网页设计中一样,增加了许多不可取的额外处理)。通常使用主RelativeLayout和几个内部LinearLayoutRelativeLayout实例(尽量不嵌套很多实例),您可以实现大多数布局。

答案 1 :(得分:0)

的StackOverflowError

当正在运行的程序的堆栈深度超过某个平台或VM特定限制时抛出。通常情况下,这只会在程序变为无限递归时发生,但也可能在正确编写(但深度递归)的程序中发生。