title: JAVA - trouble with loading a object based file
body: <p>i am having a little trouble reading a object from a text file as it preduces the following error;</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: java.util.ArrayList cannot be cast to stock.control.system.StockItem
  </code></pre>
  
  <p>which is this line;</p>
  
  <pre><code>StockItem result = (StockItem) ois.readObject();
  </code></pre>
  
  <p>below is how i save my file;</p>
  
  <pre><code>try { FileOutputStream fout = new FileOutputStream(filename);
      ObjectOutputStream oos = new ObjectOutputStream(fout);
      oos.writeObject(StockItems); }
      catch (java.io.FileNotFoundException error) {
          System.out.println("FILE NOT FOUND!");
      }
  </code></pre>
  
  <p>and here is what i have done for far for loading the file back into a object ArrayList;</p>
  
  <pre><code>  try {
          FileInputStream fis = new FileInputStream(filename);
          ObjectInputStream ois = new ObjectInputStream(fis);
          System.out.println("LOADING DATA ...");
          StockItem result = (StockItem) ois.readObject();
      ois.close();
          System.out.println(result.getItemID() + ", " + result.getItemDesc()
              + ", " + result.getPrice() + ", " + result.getQuantity() + ", "
              + result.getReOrderLevel()); // used for testing
      } catch (java.io.FileNotFoundException error) {
          System.out.println("FILE NOT FOUND!");
      } catch (IOException | ClassNotFoundException ex) {
          Logger.getLogger(StockArrayList.class.getName()).log(Level.SEVERE, null, ex);
      }
  </code></pre>
  
  <p>if anywhere could educate me so it can be done correctly it would be much appreciated.</p>