0

我正在使用 sdk 2.3.3 编写一个 android 应用程序。

我尝试使用其中包含 TableRow 的 TableLayout 布局 xml 文件。

这是布局文件:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:stretchColumns="*"
 android:weightSum="4" >

<TableRow android:id="@+id/table_row_1">

</TableRow>

在我的 GameActivity onCreate() 函数中,我有以下代码:

    super.onCreate(savedInstanceState);
    setContentView(R.layout.game);

到目前为止,我使用了一个不同的 xml 布局文件,其中包含一个运行良好的数据网格。但是由于某种原因,当我加载此布局文件时,我遇到了分段错误。

08-12 15:15:56.027: D/AndroidRuntime(1056): Shutting down VM
08-12 15:15:56.027: W/dalvikvm(1056): threadid=1: thread exiting with uncaught exception     (group=0x40015560)
08-12 15:15:56.087: E/AndroidRuntime(1056): FATAL EXCEPTION: main
08-12 15:15:56.087: E/AndroidRuntime(1056): java.lang.ArithmeticException: divide by     zero
08-12 15:15:56.087: E/AndroidRuntime(1056):     at     android.widget.TableLayout.mutateColumnsWidth(TableLayout.java:579)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at     android.widget.TableLayout.shrinkAndStretchColumns(TableLayout.java:568)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at     android.widget.TableLayout.measureVertical(TableLayout.java:466)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at     android.widget.TableLayout.onMeasure(TableLayout.java:431)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at android.view.View.measure(View.java:8313)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at android.view.View.measure(View.java:8313)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at android.view.View.measure(View.java:8313)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at android.view.View.measure(View.java:8313)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at android.os.Looper.loop(Looper.java:123)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at android.app.ActivityThread.main(ActivityThread.java:3683)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at java.lang.reflect.Method.invokeNative(Native Method)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at java.lang.reflect.Method.invoke(Method.java:507)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-12 15:15:56.087: E/AndroidRuntime(1056):     at dalvik.system.NativeStart.main(Native Method)

一般来说,我想要 4 个 tableRows 并在每个 tableRows 中添加 4 个 ImageView。

我究竟做错了什么 ?

谢谢!

克菲尔

4

1 回答 1

2

您收到“ArithmeticException:除以零”,因为表格行中没有视图。:)

于 2012-08-12T17:01:51.900 回答