contactField = new JTextField();
contactField.setBounds(165, 336, 100, 30);
contactField.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
if(!((c >= '0') && (c <= '9') || (c ==
KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))) {
e.consume();
}
}
});
int contactvalue=Integer.parseInt(contactField.getText());
通过运行此代码,我得到了:
java.lang.NumberFormatException:Forinput string: ""
答案 0 :(得分:1)
msg是描述性的:
java.lang.NumberFormatException:Forinput string:“”
Integer.parseInt(contactField.getText());
抛出异常,因为 contactField 为空..
你无法将空字符串转换为整数。