qxy1547722058 2017-04-22 01:02 采纳率: 50%
浏览 935
已采纳

程序运行就崩溃。。布局文件就一个tablelayout

package com.sptao.chess;

import android.app.*;
import android.os.*;
import android.widget.*;
import android.view.*;
import android.util.*;
import android.content.*;

public class MainActivity extends Activity
{
private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;

private final int FP = ViewGroup.LayoutParams.FILL_PARENT;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int width = dm.widthPixels;
    int height = dm.heightPixels;
    int map[][]={{0,0,0,0,0,0,0,0,0,0},//0行
    {1,0,0,0,0,0,0,0,0,0},//1
    {0,0,0,0,0,0,0,0,0,0},//2
    {0,0,0,0,1,0,0,0,0,0},//3
    {0,0,0,0,0,0,0,0,0,0},//4
    {0,0,0,0,0,0,1,0,0,0},//5
    {1,0,0,0,0,0,0,0,0,0},//6
    {0,0,0,0,0,0,0,0,0,0},//7
    {0,0,0,0,0,0,0,0,0,0}};//8.9
    int a = 0;
    Button bu []=new Button[100];
    //新建TableLayout的实例   
    TableLayout tableLayout = (TableLayout)findViewById(R.id.mainTableLayout1);  
    //全部列自动填充空白处   
    tableLayout.setShrinkAllColumns(true);  
    //生成10行,9列的表格   
    for(int row=0;row<10;row++)  //行
    {  
        TableRow tableRow=new TableRow(this);  
        for(int col=0;col<9;col++)  //列
        {  
        a++;
        switch( map[row][col])
        {
        case 0:

                break;
        default:

                bu.setTag(col+row);
                bu[a].setText("("+col+","+row"));
                tableRow.addView(bu[a]);
}


        //新建的TableRow添加到TableLayout   
        tableLayout.addView(tableRow, new TableLayout.LayoutParams(WC, WC));  
    }
}

}

  • 写回答

4条回答 默认 最新

  • ljheee 2017-04-22 01:20
    关注

    运行就崩溃,打印的日志呢...........

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效