numberformatexception in java [closed]

2020-05-10 11:50发布

When i call this function. numberformatexception occured,, how can i fix it.. help me please

public void read() throws FileNotFoundException, IOException, ClassNotFoundException, ParseException {
FileInputStream fis = null;
ObjectInputStream in = null;
File f = new File("Employee.dat");
if (f.exists()) {
fis = new FileInputStream("Employee.dat");
in = new ObjectInputStream(fis);
String x = (String) in.readObject();
String[] node = x.split("saqib");
for (int i = 0; i < node.length; i++) {
String recrd[] = node[i].split("$");
try {
AddToTail(Integer.parseInt(recrd[0]), recrd[1], recrd[2],
recrd[3], recrd[4], Integer.parseInt(recrd[5]),
recrd[6], recrd[7], recrd[8], recrd[9], recrd[10], recrd[11]);
} catch (NumberFormatException e) {
System.out.println("NumberFormatException");
}
}
in.close();
}
} 

标签: java
2条回答
成全新的幸福
2楼-- · 2020-05-10 12:32

There is nothing to fix!

This NumberFormatException is the way your program tells you that the input data are not in the format you assumed. Especially, that there is not a number in some part of the input where you expected one.

There is no way around considering the case that input data may be invalid.

查看更多
够拽才男人
3楼-- · 2020-05-10 12:36

Integer.parseInt throws NumberFormatException when the input to the method is not a valid number string i.e contains something else than digits. Input should be a string that contains a parsable integer. So make sure that you are passing the proper input to the method to avoid this exception.

查看更多
登录 后发表回答