java.lang.NullPointerException: Java Beginner

This question already has an answer here:

  • IllegalArgumentException or NullPointerException for a null parameter? [closed] 26 answers
  • What is a NullPointerException, and how do I fix it? 12 answers

  • Probably you have less than 652 lines. file.readLine() returns null when there is no more line to read.


    Use your debugger and check the variable 'file'. NullPointerException will be thrown when your variable is null and you try to call function from the null variable.


    Most likely you're calling

    file.readLine().split()
    

    after the end of the file, so file.readLine() is null.

    You could wrap the line in a null check - something like the following:

    String[] row;
    String[] rawRow = file.readLine();
    if (rawRow != null) {
        row = rawRow.split(" ");
    } else {
        break;
    }
    
    链接地址: http://www.djcxy.com/p/76196.html

    上一篇: 无法使用Intellij Idea创建可运行的jar

    下一篇: java.lang.NullPointerException:Java初学者