Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“线程中的异常”;“主要”;java.lang.NullPointerException错误_Java_Nullpointerexception_Twitter4j - Fatal编程技术网

“线程中的异常”;“主要”;java.lang.NullPointerException错误

“线程中的异常”;“主要”;java.lang.NullPointerException错误,java,nullpointerexception,twitter4j,Java,Nullpointerexception,Twitter4j,请帮帮我。我的代码中出现空指针异常错误。这是: File strfile = new File("15.json"); Scanner scan = new Scanner (strfile); while(scan.hasNextLine()) { String line = scan.nextLine(); Status statjson = DataObjectFactory.createStatus(json);

请帮帮我。我的代码中出现空指针异常错误。这是:

    File strfile = new File("15.json");
    Scanner scan = new Scanner (strfile);

    while(scan.hasNextLine())
    {
        String line = scan.nextLine();
        Status statjson = DataObjectFactory.createStatus(json);
        String text = statjson.getText();

    if (text == null)
    {
        System.out.print("null");
    }
           else { System.out.print(text); }     }

它在前几行有“text”字段时运行,但当它遇到没有“text”字段的行时,会抛出null指针异常,而不是在控制台上打印“null”。救命啊

使用
==
操作符检查对象引用

if (text == null)
更改此项:

if(text.equals(null))
致:


如果“text”为null,text.equals将抛出NPE。使用==运算符。

我发现可能有两个(可能有三个)地方可以获得NPE。你(特别是)用哪一行?谢谢你的快速回复。我刚刚做了,但仍然有同样的错误。你能给我们看一下stacktrace,以及你得到异常的确切行吗?stacktrace显示了什么?你能帮我们寄吗?
if(text == null)