JTextField创建了二维数组 但一直报错空指针 求大神解答
public class 成绩录入界面 extends JFrame{JTextField[][] scores;
String[] course;
String[] name;
int[][] score;
public 成绩录入界面() throws IOException{
JTextField[][] scores= new JTextField[10][6];
for(int i=0;i<scores.length;i++){
for(int j=0; j<scores[i].length;j++){
scores[i][j]=new JTextField();
}
}
JPanel p1=new JPanel();
p1.setLayout(new GridLayout(11,6,0,0));
p1.add(new JLabel("姓名"));
DataInputStream Input1 = new DataInputStream(new FileInputStream("a.txt"));
try{while(true)
{p1.add(new JLabel(Input1.readUTF()));
}
}
catch(EOFException ex){
}
for(int i=0;i<scores.length;i++){
for(int j=0; j<scores[i].length;j++){
p1.add(scores[i][j]);
}
}
add(p1);
JPanel p2=new JPanel(new GridLayout(1,3,10,10));
JButton a=new JButton("确认");
JButton b=new JButton("返回");
JButton c=new JButton("继续添加");
p2.add(a);
p2.add(b);
p2.add(c);
add(p1,BorderLayout.CENTER);
add(p2,BorderLayout.SOUTH);
a.addActionListener(new ButtonListener());
b.addActionListener(new bListener());
c.addActionListener(new cListener());
}
private class ButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
已保存窗口 frame=new 已保存窗口();
frame.setTitle("");
frame.setSize(300,180);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
try {
DataOutputStream ou=new DataOutputStream(new FileOutputStream("a.txt",true));
for(int i=0;i<10;i++){
try {
ou.writeUTF(scores[i][0].getText());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}}
是这样 每次我运行到aListener的时候经常要报错 说空指针 是JTEXTFIELD【】【】读不出来吗?我都卡了好久了 求大神解答!!
补充:Java , Java SE