我的代码在eclipse中编译得很好,但是当我在命令提示符下运行它时,我得到一个空指针,第19行除外。null在我的代码中没有用到。请帮助空指针除
public class lab4 {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader (isr);
ArrayList<String> studentInfo;
studentInfo = new ArrayList<String>();
String students = br.readLine();
String [] answers = students.split ("\\s+");
while(!students.equalsIgnoreCase("zzzz")){
students = br.readLine();
studentInfo.add(students);
}
String [] s0 = studentInfo.get(0).split ("\\s+");
这就是问题所在区域它一直指着我:
while(!students.equalsIgnoreCase("zzzz")){
students = br.readLine();
studentInfo.add(students);
}
添加如果(br.readLine()!= NULL)从缓冲区读取做着里面前while循环。 – 2015-10-05 00:51:50
我添加了代码,它仍然做同样的事情? –
其实添加如果((学生= br.readline())!=空)代替学生= br.readLine();你也需要在你第一次从缓冲区读取代码的前面部分进行空检查 – 2015-10-05 01:05:09