每当我运行此代码时,我都会继续:
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at UseEmployeeRecord.main(UseEmployeeRecord.java:24)
作为输出。
// The "UseEmployeeRecord" class.
import java.awt.*;
import hsa.Console;
import java.io.*;
public class UseEmployeeRecord {
public static void main (String[] args) throws IOException {
BufferedReader fr = new BufferedReader (new FileReade("employees.txt"));
String name;
int num;
double hr, hw;
EmployeeRecord employee[] = new EmployeeRecord [10];
for (int i = 0 ; i < employee.length ; i++)
{
name= fr.readLine ();
num = Integer.parseInt (fr.readLine ());
hr = Double.parseDouble (fr.readLine ());
hw = Double.parseDouble (fr.readLine ());
employee [i] = new EmployeeRecord (name, num, hr, hw);
}
}
}
答案 0 :(得分:0)
您尚未粘贴employees.txt的内容
例外情况很明显。
如果employees.txt中的值是字符串表示“整数”,例如
Integer.parseInt("1")
不会抛出异常,但肯定Integer.parseInt(null)
或Integer.parseInt("x")
会抛出异常。因此,对于调试,请打印readLine
的值,看看它是否真的代表整数。