java.lang.NullPointerException
at videostore.BinaryFile.adderoo(BinaryFile.java:47)
at videostore.VideoStore.jButton1ActionPerformed(VideoStore.java:384)
at videostore.VideoStore.access$100(VideoStore.java:17)
at videostore.VideoStore$2.actionPerformed(VideoStore.java:189)
Line 47: if (videosList == null || videosList.size() == 0)
Line 384:BinaryFile.adderoo(vid);
Which refers to the following method:
public void adderoo(Video v) {
if (videosList == null || videosList.size() == 0) {
videosList = new ArrayList<>(10);
}
videosList.add(v);
}
line 17: public class VideoStore extends javax.swing.JFrame {
Line 189: jButton1ActionPerformed(evt);
Essentially I'm trying to add a Video object to an Arraylist I have created named videosList. However every time I try, I get that Exception and I'm not sure why, because I initialized the ArrayList with a size..
initializing the arraylist in my BinaryFile class: public static ArrayList<Video> videosList;
Then I have a method named load, which I run in my main videoStore class in it's constructor:
public void load() throws Exception {
BufferedReader br = new BufferedReader(new FileReader(FILE_NAME));
if (br.readLine() != null) {
try {
File log = new File(FILE_NAME);
FileInputStream fileIn = new FileInputStream(log);
ObjectInputStream in = new ObjectInputStream(fileIn);
ArrayList<Video> videosList = (ArrayList)in.readObject();
in.close();
fileIn.close();
} catch (Exception i) {
i.printStackTrace();
}
} else {
ArrayList<Video> videosList = new ArrayList<>(10);
}
br.close();
}
The intention of this method is to check if a file contains an ArrayList already, and if it contains it, it de-serializes it and places it into the ArrayList.
I feel like I've covered all the stops, so I'm stumped as to why the exception is occurring.