0

I download an open source file and try to run it but I face a problem

the function that I face the problem with it listed as follows:

public class FileUtil {
    private Logger logger = Logger.getLogger(FileUtil.class);

    public List<String> loadDataSet(String fileName) {

        List<String> stringsFromFile = new ArrayList<>();
        String str = "";

        //  ClassLoader.getResourceAsStream
        try (InputStream is = getClass().getClassLoader().getResourceAsStream(fileName)) {
            //System.out.println(is);
             BufferedReader reader = new BufferedReader(new InputStreamReader(is));

            if (is != null) {
                while ((str = reader.readLine()) != null) {
                    stringsFromFile.add(str);
                }
            }

        } catch (FileNotFoundException e) {
            logger.error(e);
        } catch (IOException e1) {
            logger.error(e1);
        }

        return stringsFromFile;
    }
}

the fileName = "/src/resources/DataSets/wiki-Vote.txt"

the runtime error showed in the following

1689 [Thread-1] DEBUG main.java.App.Datasets.DataSetController  - Start load DataSet:Facebook circles
Exception in thread "Thread-1" java.lang.NullPointerException
    at java.io.Reader.<init>(Reader.java:78)
    at java.io.InputStreamReader.<init>(InputStreamReader.java:72)
    at main.java.App.Common.Utils.FileUtil.loadDataSet(FileUtil.java:25)
    at main.java.App.Datasets.DataSetController.loadDataSet(DataSetController.java:71)
    at main.java.App.Common.UITasks.DataSetLoaderTask$1.run(DataSetLoaderTask.java:30)
    at java.lang.Thread.run(Thread.java:745)

note: I try different path but still the same problem and I read many questions but I cant solve they mention that the problem from the classpath of the jars but really I am not expert because of that I can't figure out how to solve it by the way they told the others please explain in details thank you very much

0 Answers0