线程主java.lang.ΝullPointerException

时间:2017-05-24 16:25:19

标签: java nullpointerexception

您好我正在制作一个程序,当我运行它时,它会向我显示以下消息:线程主java.lang.nullpointerexception中的异常 在FileReader.readfile(TestFiles.java:53) 在TestFiles.main(TestFiles.java:240)

所以这里的问题似乎出现在我的程序中

class FileReader
{
 private String path;
 private File object;
 private Scanner inputReader;
 private String Line;
 public FileReader(String path)
 {
    this.path=path;

 }
 public boolean initReader()
 {

   object = new File(path);

   Scanner inputReader = null;

    try
    {
        inputReader = new Scanner(new FileInputStream("universities.txt"));
    }
    catch(FileNotFoundException e)
    {
        System.out.println("File universities.txt was not found");
        System.exit(0);
    }

    if (object.exists())
    {
        return true;

    }else
    {
        return false;
    }
}

public ArrayList<String> readFile()
{   
    ArrayList<String> myList = new ArrayList<String>();


        while(inputReader.hasNextLine()); //here is the line:53
            myList.add(Line);

        myList.remove(0);   

        return myList;
}
public void closeReader()
{
    inputReader.close();
}

}

主要在这里

public class TestFiles 
 {
   public static void main(String[] args)
   {
    FileReader reader = new FileReader("universities.txt");
        if(reader.initReader()){
            FileEditor editor = new FileEditor(reader.readFile()); //here is the line 240
            reader.closeReader();
            editor.fillHashMap();
            FileWriter writer = new FileWriter("universities_2015_output.txt");
            if(writer.initWriter()){
                writer.writeFile(editor.getScoresOfYear(2015));
                writer.closeWriter();
        }
        else{
            System.out.println("Error creating file");
        }
        System.out.println("Average university score of year 2015: "+editor.getAverageOfYear(2015));
        System.out.println("Min university score of year 2015: "+editor.getMinOfYear(2015));
        System.out.println("Max university score of year 2015: "+editor.getMaxOfYear(2015));
    }
    else{
        System.out.println("Error opening file");
    }
}

}

我已经阅读过这个问题,我认为我的问题出在输入读取器上,显示为null。任何想法都会有所帮助。我必须在本周完成这个程序,所以我需要你的帮助来完成它。 谢谢

0 个答案:

没有答案