title: Java Serialization - readbObject works, but operations on the read object do not work
body: <p>So I've created a program that can create / store / and manipulate tests and surveys. I serialize the objects created, save, load and utilize them. </p>
  
  <p>So far, everything with the serialization works, however when I try to load Test / Survey Objects, I can't, for instance, print the questions and possible answers associated with the Test / Survey.</p>
  
  <p>Below is the code inside the FileLoader class which is responsible for saving and loading documents:</p>
  
  <pre><code>//--------------------------------------------------------------------------
  /// Method : saveDocument
  /// @Description - saves test to a file
  /// @param[in] &lt;test&gt; - a test object to save
  /// @return &lt;void&gt;
  //--------------------------------------------------------------------------
  public void saveDocument(AbstractQuestionContainer document)
  {
      container = document;
  
      try
      {
          ObjectOutputStream objectOutput = new ObjectOutputStream(file);
          objectOutput.writeObject(container);
  
          objectOutput.close();           
      }
      catch(FileNotFoundException e)
      {
          System.out.println("Error Finding File: " + e.getMessage());
      }
      catch(IOException e)
      {
          System.out.println("Error Saving Test: " + e.getMessage());
          e.printStackTrace();
      }
      catch(NullPointerException e)
      {
          System.out.println("Error: " + e.getMessage());
      }
  }
  
  
  
  //------------------------------------------------------------------------------
  /// Method : loadDocument
  /// @Description - loads documentName into an object
  /// @param[in] &lt;documentName&gt; - the name of the document to load
  /// @return &lt;void&gt;
  //------------------------------------------------------------------------------
  
  public AbstractQuestionContainer loadDocument() throws IOException
  {
      container = new AbstractQuestionContainer();
  
      try
      {
          FileInputStream inputStream = new FileInputStream(workingFile);
          ObjectInputStream objectInput = new ObjectInputStream(inputStream);
  
         container = (AbstractQuestionContainer) objectInput.readObject();
  
         objectInput.close();
      }
      catch(ClassNotFoundException e)
      {
          System.out.println("ClassNotFoundException: " + e.getMessage());
      }
      catch(EOFException e)
      {
          // do nothing
      }
  
      return container;
  }
  </code></pre>
  
  <p>Again, the only functionality that I need to use with loaded objects is the ability to print out the questions associated with Test and their possible answers. When I make the printDocument call in the Driver class, nothing gets displayed. To me, this indicates that the object is loaded, but not loaded properly somehow. </p>
  
  <p>I've scoured Stack relating to Object Serialization and have not found anything that helps in relation to this matter. Any and all help is greatly appreciated. Thanks.</p>
  
  <p>Edit: Here is how the code is called:</p>
  
  <pre><code>    if(buildBuffer.size() == 1)
      {
          AbstractQuestionContainer document = buildBuffer.get(0);
          loader.saveDocument(document);
          buildBuffer.remove(0);
  
          System.out.println(documentToSave + " has been saved.");
          System.out.println();
      }
      else
      {
          // loop over build buffer and find file
          for(int i = 0; i &lt; buildBuffer.size(); i++)
          {   
              if(buildBuffer.get(i).fileName().equals(loader.getFileName()))
              {
                  loader.saveDocument(buildBuffer.get(i));
  buildBuffer.remove(i);                                                          
              }
          }
  
          System.out.println(documentToSave + " has been saved.");
          System.out.println();
      }
  </code></pre>
  
  <p>And the loading:</p>
  
  <pre><code>// if the size of the build buffer is 1, then there's only one thing to load, so load it.
  if(buildBuffer.size() == 1)
  {
      loadBuffer.add(buildBuffer.get(0));
      buildBuffer.remove(0);
  
      System.out.println("Document " + documentToLoad + " loaded to the buffer successfully");
      System.out.println();
      break;
  }
  else
  {
      for(int i = 0; i &lt; buildBuffer.size(); i++)
      {
          if(buildBuffer.get(i).fileName().equals(loader.getFileName()))
          {
              loadBuffer.add(buildBuffer.get(i));
              buildBuffer.remove(0);
  
              System.out.println("Document " + documentToLoad + " loaded to the buffer successfully");
              System.out.println();
              break;
          }
      }
  }
  
  // check to see if given file is in local directory
  boolean exists = new File(filePath, documentToLoad).exists();
  
  // if the file exists, load it, and add it to the loadBuffer
  if(exists)
  {
      container = loader.loadDocument();
      loadBuffer.add(container);
  
      System.out.println("Document " + documentToLoad + " loaded to the buffer successfully");
      System.out.println();
  }
  else
  {
      System.out.println("Error: File entered does not exist in either the buildBuffer or local directory.");
      System.out.println();
      continue;
  }
  </code></pre>