(年龄输入框)用getText()获得字符串怎么转换成整形?
我写的程序:
tf_age = new JTextField();
String ag = tf_age.getText();
if(ag.trim()!=""){
age = Integer.parseInt(ag);
}else{
age=-1;
}
tf_age.setBounds(111, 257, 112, 18);
getContentPane().add(tf_age);
但会报错:java.lang.NumberFormatException: For input string: ""
不知是什么原因?应该怎样写才对?