title: Loading an array of objects using Java Serialization
body: <p>The following code is two methods, one for saving to a file using object serialization and one for loading and deserializing the saved file for the user to read:</p>
  
  <pre><code>private void SaveDeck() throws Exception {
      ObjectOutputStream oos = null;
      FileOutputStream fout = null;
      try{
          fout = new FileOutputStream(filePath, true);
          oos = new ObjectOutputStream(fout);
          oos.writeObject(theDeck);
      } catch (Exception ex) {
          ex.printStackTrace();
      }finally {
          if(oos  != null){
              oos.close();
          } 
      }
  }
  
  private FlashCardDeck[] loadDeck(){
      user.setDeckMade(true);
      try {
          FileInputStream fis = new FileInputStream(filePath);
          ObjectInputStream in = new ObjectInputStream(fis);
          this.theDeck = (FlashCardDeck[])in.readObject();
          in.close();
      }
      catch (Exception e) {
          System.out.println(e);
      }
      return theDeck;
  }
  </code></pre>
  
  <p>The error I'm getting is on the load method: </p>
  
  <p><code>java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: myPackage.UserInterface
  </code></p>
  
  <p>Saving works fine; I've opened up the .ser file after the SaveDeck method has executed and everything seemed to check out properly.</p>
  
  <p>My question is if the problem is with the file itself, the save method, or external methods? I have made sure that everything not serializable (Namely, the Scanner class) is transient.</p>
  
  <pre><code>package myPackage.FlashCards;
  
  import java.io.Serializable;
  
  public class FlashCardDeck implements Serializable{
  
  
  private static final long serialVersionUID = -1176413113990886560L;
  public FlashCard[] theDeck;
  public String deckName;
  
  
  public FlashCardDeck(int cards, String name) {
      this.deckName = name;
      theDeck = new FlashCard[cards];
      for (int i = 0; i &lt; theDeck.length; i++) {
          theDeck[i] = new FlashCard(i);
      }
  }
  
  public String getQuestion(int i) {
      return theDeck[i].QuestionToString();
  }
  
  public String getAnswer(int i ) {
      return theDeck[i].AnswerToString();
  }
  
  public String getName() {
      return deckName;
  }
  
  public int getDeckSize() {
      return theDeck.length;
  }
  
  
  }
  
  
  package myPackage.FlashCards;
  
  import java.io.Serializable;
  import java.util.Scanner;
  
  
  public class FlashCard implements Serializable{
  
  private static final long serialVersionUID = -8880816241107858648L;
  
  private transient Scanner in = new Scanner(System.in);
  
  String question;
  String answer;
  
  public FlashCard(int i) {
      setCard(i);
  }
  
  public void setCard(int cards) {
      System.out.println("What is the question for number " + (cards + 1) + "?");
      question = in.nextLine();
      System.out.println("What is the answer for number " + (cards + 1) + "?");
      answer = in.nextLine();
  
  }
  
  public String QuestionToString() {
      return "Question: " + question;
  }
  
  public String AnswerToString() {
      return "Answer: " + answer;
  }
  
  
  
  
  }
  
  
  package myPackage.FlashCards;
  
  import java.io.Serializable;
  import java.util.InputMismatchException;
  import java.util.Scanner;
  
  
  public class UserInterface implements Serializable{
  
  private static final long serialVersionUID = 7755668511730129821L;
  private int moreThanOnce = 0;
  boolean deckMade = false;
  
  private transient Scanner in = new Scanner(System.in);
  
  public int AmountOfDecks() {
      int decks;
      System.out.println("How many decks will you be creating? (Type the number, 
              not the word. Ex: 2)");
      decks = in.nextInt();
      while (decks &lt;= 0) {
          System.out.println("You can't have less than one deck! Try again.");
          decks = in.nextInt();
      }
      return decks;
  }
  
  
  public int StartMenu() {
      int choice = 0;
      moreThanOnce++;
      if (moreThanOnce &gt; 1) {
          choice = SecondMenu();
      } else {
  
          System.out.println("\nFlash Card Creation Engine Ver. 2.5 ALPHA");
          System.out.println("Press the cooresponding number for your 
                      choice.");
          System.out.println("1. Make a deck of flash cards");
          System.out.println("2. Play flash cards");
          System.out.println("3. Quit \n");
  
          try { choice = in.nextInt(); } catch (InputMismatchException ime) {}
      }
  
      return choice;
  }
  
  public int AmountOfCards(int cards) {
      int catchMe;
      deckMade = true;
      System.out.println("How many cards would you like? (Type the number, not the 
              word. Ex: 2)");
      try {
          catchMe = in.nextInt();
          while (catchMe &lt;= 0) {
              System.out.println("You can't have less than one card! Try 
                              again!");
              catchMe = in.nextInt();
          }
      } catch (Exception ime) {
          System.out.println("Uh-oh, you did that wrong! Let's try that again. 
                      Try typing: 3");
          cards = 0;
          catchMe = in.nextInt();
      }
  
      cards = catchMe;
      return cards;
  }
  
  public boolean getDeckMade() {
      return deckMade;
  }
  
  public void setDeckMade(boolean makeDeckMade) {
      this.deckMade = makeDeckMade;
  }
  
  public String NameOfDeck() {
      String name;
      System.out.println("What would you like to name this deck?");
      name = in.next();
      return name;
  }
  
  private int SecondMenu() {
      int choice = 0;
      System.out.println("Now what would you like to do?");
      if (deckMade) {
          System.out.println("1. Make or load a deck of flash cards -- DONE");
      } else {
          System.out.println("1. Make a deck of flash cards.");
      }
      System.out.println("2. Play flash cards");
      System.out.println("3. Quit \n");
  
      try { choice = in.nextInt(); } catch (InputMismatchException ime)  {}
      return choice;
  }
  
  public boolean SetMode() {
      boolean timed = false;
      int userChoice = 0;
      while (userChoice &lt; 1 || userChoice &gt; 2) {
          System.out.println("What mode are you selecting?");
          System.out.println("1. Timed");
          System.out.println("2. Normal");
          System.out.println("3. Help");
          System.out.println("4. Quit");
          userChoice = in.nextInt();
          if (userChoice == 1) {
              timed = true;
          } else if (userChoice == 3) {
              System.out.println("Timed: Answers to a flash card will 
                              appear after a set amount of seconds, then show the next  
                              question after the same amount of seconds, which are set by 
                              the user (that's you!)");
              System.out.println("Normal: Answers to a flash card will 
                              appear when the user (also you!) presses enter, and wait for 
                              enter to be pressed before showing the next question.");
          } else if (userChoice == 4) {
              System.out.println("Have a good day.");
              System.exit(0);
          } else {
              System.out.println("Choose from the proivded list -- 1 for 
                              Timed mode, 2 for Normal mode, 3 to show the Help menu, 4 to 
                              quit.");
              System.out.println();
  
          }
      }
  
      return timed;
  }
  
  public String setQuestion(int cards) {
      String question = "";
  
      return question;
  
  }
  
  public String setAnswer(int cards) {
      String answer = "";
      return answer;
  }
  
  
  }
  </code></pre>