我需要帮助在android studio中创建一个表,请查看我的代码并帮助我...当我想在我的设备中运行时,此代码有错误!
TableLayout table=new TableLayout(this);
public void _start(View v) {
CreateTable();
}
public void CreateTable() {
for (int row = 0; row < 3; row++) {
TableRow groupCells = new TableRow(this);
for(int column=0;column<3;column++) {
TextView cell = CreateCells(row, column);
groupCells.addView(cell);
}
table.addView(groupCells);
}
}
private TextView CreateCells(int row, int column) {
TextView cell = new TextView(this);
cell.setId(Integer.valueOf(row + "," + column));
cell.setWidth(20);
cell.setHeight(20);
cell.setText("");
cell.setX((findViewById(R.id._table).getWidth()/2)-(20*row)+(cell.getWidth()/2));
cell.setY((findViewById(R.id._table).getHeight()/2)-(20*column)+(cell.getHeight()/2));
cell.setVisibility(View.VISIBLE);
return cell;
}
我有这个错误:
Android.widget.TableRow.onMeasure(TableRow.java)上android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1368)的android.widget.LinearLayout.forceUniformHeight(LinearLayout.java:1380)中的java.lang.NullPointerException :114)在android.view.vision.measure(View.java:17430)的android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)在android位于android.widget.TableLayout.measureVertical(TableLayout.java:476)的android.widget.TableLayout上的android.widget.LinearLayout.measureVertical(LinearLayout.java:722).widget.TableLayout.measureChildBeforeLayout(TableLayout.java:464)。 onMeasure(TableLayout.java:439)位于android.view.measure.View.measure(View.java:17430),位于android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java)的android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463) :1436)在android.widget.LinearLayout.measu在Android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java)的android.view.View.measure(View.java:17430)的android.widget.LinearLayout.onMeasure(LinearLayout.java:615)上的reHorizontal(LinearLayout.java:1083) :727)在android.view.vision.measure(View.java:17430)上的android.view.measure.View.Starts(ViewGroup.java:5463)的android.widget.RelativeLayout.onMeasure(RelativeLayout.java:463) .widget.FrameLayout.onMeasure(FrameLayout.java:430)在Android.w.L.关于Android.widget.LinearLayout的android.view.vision.measure(View.java:17430)android.widget.LinearLayout.measureVertical(LinearLayout.java:875)。 onMeasure(LinearLayout.java:613)位于android.widget.Line中的android.widget.Lineout.measureVerical(LinearLayout.java:875)上的android.view.View.measure(View.java:17430)(LinearLayout.java:675) :613)在android.view.View.measure(View.java:17430)我不知道这是什么! 请帮帮我......