0

I am trying to read from a binary file that has data (the writing works).Ive attached major parts of the error and added the function I call while I am building my controller:

...
Caused by: java.lang.NullPointerException: Cannot invoke "java.util.Vector.add(Object)" because "this.listeners" is null
    at mvc_election.model.Election.addListener(Election.java:64)
    at mvc_election.controller.ElectionController.<init>(ElectionController.java:22)
    at application.Election_main.start(Election_main.java:31)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:474)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:447)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:446)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    ... 1 more
Exception running application application.Election_main

____________

ElectionController ec = new ElectionController(Election.read(), aev);

____________

public static Election read()
            throws FileNotFoundException, IOException, ClassNotFoundException, NotSerializableException {
        ObjectInputStream inFile = null;
        try {
            inFile = new ObjectInputStream(new FileInputStream("Elections.dat"));
            Election temp = (Election) inFile.readObject();
            inFile.close();
            return temp;
        } catch (NotSerializableException nse) {
            System.out.println(nse.getMessage());
        }
        return null;
    }    
  • 1
    That blob of text? That is called a stack trace. You should read it. It tells you that the problem occurs in line 64 of your Election.java file. You didn't paste that part. The part you did paste (the `read` method) is completely irrelevant here. – rzwitserloot Jul 04 '21 at 20:14

0 Answers0