因为JOptionPane.showInputDialog如果你按的是取消,返回的是null
所以你在后面在用temp这个String时就会报java.lang.NullPointerException
因此你要判断JOptionPane.showInputDialog的返回值是否为空
所以你在后面在用temp这个String时就会报java.lang.NullPointerException
因此你要判断JOptionPane.showInputDialog的返回值是否为空
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
String temp="";
temp=JOptionPane.showInputDialog("Please input a value");
try{
if(temp.trim().equals(""))
System.exit(0);
else {
size=Integer.parseInt(temp);
// try {
jbInit();}
}
//}
catch(Exception e) {
System.out.println(temp);
e.printStackTrace();
}
}
System.exit(0);}
System.exit(0);
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
String temp="";
try{ //try的位置
temp=JOptionPane.showInputDialog("Please input a value");
size=Integer.parseInt(temp);
jbInit();
}
catch(NullPointerException e) {
System.out.println(temp);
e.printStackTrace();
}
}
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
String temp=""; try{
temp=JOptionPane.showInputDialog("Please input a value");
if(temp.trim()==null)
System.exit(0);
else {
size=Integer.parseInt(temp);
// try {
jbInit();}
}
//}
catch(Exception e) {
System.out.println(temp);
e.printStackTrace();
}
我改成这样写了,可是为什么还是会提示错误,并且还会初始化产生一个frame,而不是推出系统?