Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.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 为什么我得到一个空指针异常?(初学者)_Java_Eclipse - Fatal编程技术网

Java 为什么我得到一个空指针异常?(初学者)

Java 为什么我得到一个空指针异常?(初学者),java,eclipse,Java,Eclipse,我对此感到非常沮丧,并且已经尝试了好几天来修复它。我有两个班,Main和GetNounList 主要内容: import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws FileNotFoundException { GetNounList nouns = new GetNounList(); }// end main method

我对此感到非常沮丧,并且已经尝试了好几天来修复它。我有两个班,Main和GetNounList

主要内容:

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {
    GetNounList nouns = new GetNounList();

}// end main method
}//end of Main class
获取列表:

import java.io.*;
import java.util.*;

public class GetNounList extends Main {
ArrayList<String> listOfWords;

public GetNounList() throws FileNotFoundException {
    Scanner list = new Scanner(new File(
    "/Users/FareedMabrouk/Desktop/Explore/Coding/Java/BusinessIdeaGenerator/CodeRepository/BusinessGen/src/Nouns.txt"));

while (list.hasNextLine()) {
        listOfWords.add(list.nextLine());
    } // end while loop
    System.out.println(listOfWords);
}//end constructor
}//end GetNounList class
等等


唯一的错误是将文件中的名词添加到arraylist的行中的nullpointer异常。有人能帮我一下吗?

listOfWords
从来没有构建过

替换

ArrayList<String> listOfWords;
arraylistlistofwords;

listOfWords=newarraylist();

你没有初始化列表哦,天哪,非常感谢你你不知道这有多让我生气
ArrayList<String> listOfWords;
List<String> listOfWords=new ArrayList<>();