Java中关于NullPointerException的错误
源代码如下:importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importcom.bruceecke...
源代码如下:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import com.bruceeckel.swing.*;
public class TicTacToe extends JApplet {
private JTextField
rows = new JTextField("3"),
cols = new JTextField("3");
private static final int BLANK = 0, XX = 1, OO = 2;
class ToeDialog extends JDialog {
private int turn = XX; // Start with x's turn
ToeDialog(int cellsWide, int cellsHigh) {
setTitle("The game itself");
Container cp = getContentPane();
cp.setLayout(new GridLayout(cellsWide, cellsHigh));
//111111111111111111
for(int i = 0; i < cellsWide * cellsHigh; i++)
cp.add(new ToeButton());
//222222222222222222
//ToeButton[] tb=new ToeButton[cellsWide*cellsHigh];
//for(int=0;i<tb.length;i++)
//cp.add(tb[i]);
setSize(cellsWide * 50, cellsHigh * 50);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
} 展开
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import com.bruceeckel.swing.*;
public class TicTacToe extends JApplet {
private JTextField
rows = new JTextField("3"),
cols = new JTextField("3");
private static final int BLANK = 0, XX = 1, OO = 2;
class ToeDialog extends JDialog {
private int turn = XX; // Start with x's turn
ToeDialog(int cellsWide, int cellsHigh) {
setTitle("The game itself");
Container cp = getContentPane();
cp.setLayout(new GridLayout(cellsWide, cellsHigh));
//111111111111111111
for(int i = 0; i < cellsWide * cellsHigh; i++)
cp.add(new ToeButton());
//222222222222222222
//ToeButton[] tb=new ToeButton[cellsWide*cellsHigh];
//for(int=0;i<tb.length;i++)
//cp.add(tb[i]);
setSize(cellsWide * 50, cellsHigh * 50);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
} 展开
展开全部
报错的时候他会提示错误出现的行数是哪一行。。。看那一行 找"." 点前面的对弯耐象获取的时候是空的凳闹橡。。。这样枣旁解释 楼主明白么?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
就是对象没有初始化的结果~~~这异常是最常见的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
对象没有初始化就应用了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询