Java在一个类中调用另一个类的方法,报错空指针异常,主要代码和出错位置如下: 5
publicclassTireselectextendsJFrameimplementsActionListener{privateMainviewmv;//程序主界面p...
public class Tireselect extends JFrame implements ActionListener {
private Mainview mv;//程序主界面
private JTextField[] jt;//
private int i;
private String str = "";
public JTextField[] getJtn() {
return jt;
}
Tireselect(){
this.setSize(800, 600);
this.setVisible(true);
jt = new JTextField[25];
for(i=0;i<25;i++){
jt[i] = new JTextField("0");
this.add(jt[i]);
this.add(jpt);
}
JButton jbu = new JButton("提交!");
this.add(jbu);
jbu.addActionListener((ActionListener) this);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String cmd = e.getActionCommand();
if(cmd.equals("提交!")){
for(i = 0;i<25;i++){
String b = jt[i].getText();
str = str +b+"\r\n";
mv.getJok().setText(str);//将字符串注入主界面一个JTextArea中,报错空指针异常
}
}
}
public String getStr() {
return str;
}
public void setStr(String str) {
this.str = str;
}
public Tireselect(String str){
this.str = str;
}
} 展开
private Mainview mv;//程序主界面
private JTextField[] jt;//
private int i;
private String str = "";
public JTextField[] getJtn() {
return jt;
}
Tireselect(){
this.setSize(800, 600);
this.setVisible(true);
jt = new JTextField[25];
for(i=0;i<25;i++){
jt[i] = new JTextField("0");
this.add(jt[i]);
this.add(jpt);
}
JButton jbu = new JButton("提交!");
this.add(jbu);
jbu.addActionListener((ActionListener) this);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String cmd = e.getActionCommand();
if(cmd.equals("提交!")){
for(i = 0;i<25;i++){
String b = jt[i].getText();
str = str +b+"\r\n";
mv.getJok().setText(str);//将字符串注入主界面一个JTextArea中,报错空指针异常
}
}
}
public String getStr() {
return str;
}
public void setStr(String str) {
this.str = str;
}
public Tireselect(String str){
this.str = str;
}
} 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏5(财富值+成长值)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询