我正在使用sdk 2.3.3编写一个Android应用程序。
我尝试使用TableLayout布局xml文件,里面有TableRow。
这是布局文件:
<?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,每个都要添加4个ImageViews。
我做错了什么?
谢谢!
幼狮
答案 0 :(得分:2)
您收到“ArithmeticException:除以零”,因为表格行中没有视图。 :)