0

为什么在回调函数中执行时会引发以下代码异常?

public class TeamPointsDayActivity extends Activity implements IMyCallBack<String>, IMyCallBackTeamPoints {

    private String mDay; 
    private URLHandler mUrlHandler;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_team);
        getActionBar().setDisplayHomeAsUpEnabled(true);

        Intent intent = getIntent();
        mDay = intent.getStringExtra(MainActivity.EXTRA_DAY);   
        // !!!!!Calling createTable() here works fine!!!!

    }

    private void createTable() {
        TableLayout table = (TableLayout)findViewById(R.id.mytabletest);

        TableRow tr = new TableRow(TeamPointsDayActivity.this);
        tr.setLayoutParams(new TableRow.LayoutParams(
                LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT)); 
        tr.setPadding(8, 8, 8, 8);

        TextView labelTV = new TextView(TeamPointsDayActivity.this);
        labelTV.setText("test1111111");
        labelTV.setBackgroundResource(R.drawable.cell_shape);
        labelTV.setPadding(3, 3, 3, 3);
        tr.addView(labelTV);        
        table.addView(tr, new TableRow.LayoutParams(
                LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));    
    }

    public void onTeamPointsReadComplete(IGameData data) {
    // Do stuff with "data"...not relevant
        // Adding following line here in this callback function will throw an exception
    createTable();

    }
}


09-13 16:23:32.114: E/AndroidRuntime(799): FATAL EXCEPTION: main
09-13 16:23:32.114: E/AndroidRuntime(799): java.lang.ArithmeticException: divide by zero
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.widget.TableLayout.mutateColumnsWidth(TableLayout.java:583)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.widget.TableLayout.shrinkAndStretchColumns(TableLayout.java:572)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.widget.TableLayout.measureVertical(TableLayout.java:470)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.widget.TableLayout.onMeasure(TableLayout.java:435)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.view.View.measure(View.java:15172)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.view.View.measure(View.java:15172)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.view.View.measure(View.java:15172)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.view.View.measure(View.java:15172)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-13 16:23:32.114: E/AndroidRuntime(799):  at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.view.View.measure(View.java:15172)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1848)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1100)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1273)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.view.Choreographer.doCallbacks(Choreographer.java:555)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.view.Choreographer.doFrame(Choreographer.java:525)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.os.Handler.handleCallback(Handler.java:615)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.os.Handler.dispatchMessage(Handler.java:92)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.os.Looper.loop(Looper.java:137)
09-13 16:23:32.114: E/AndroidRuntime(799):  at android.app.ActivityThread.main(ActivityThread.java:4745)
09-13 16:23:32.114: E/AndroidRuntime(799):  at java.lang.reflect.Method.invokeNative(Native Method)
09-13 16:23:32.114: E/AndroidRuntime(799):  at java.lang.reflect.Method.invoke(Method.java:511)
09-13 16:23:32.114: E/AndroidRuntime(799):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-13 16:23:32.114: E/AndroidRuntime(799):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-13 16:23:32.114: E/AndroidRuntime(799):  at dalvik.system.NativeStart.main(Native Method)

真的很奇怪……

有人可以告诉我这里有什么问题吗?否则,我应该如何使用来自回调函数的数据创建动态表行?

编辑:忘记发布 activity_select_team.xml 文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:id="@+id/playerlayout" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="1" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="2" />

    <TableLayout
        android:id="@+id/mytabletest"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
     android:shrinkColumns="*"  
    android:stretchColumns="*"
    android:background="@drawable/round" >

    <TableRow
        android:id="@+id/row1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="8dp" >       
    </TableRow>

    </TableLayout>

</LinearLayout>

问候, 桑德罗

4

0 回答 0