title: Serialize objects into a dat file
body: <p>So i have this array list of objects i would like to store into a dat file in binary format .</p>
  
  <p>the objectA class has this constructor</p>
  
  <pre><code>public ObjectA(String aString,int aNumber ,String[] sampleA){
      this.aString = aString;
      this.aNumber = aNumber;
      this.sampleA= sampleA;
  }
  </code></pre>
  
  <p>in another class file i instantiated this on the class and have filled the arraylist with ObjectA objects</p>
  
  <pre><code>      private static ArrayList&lt;ObjectA&gt; objectA = new ArrayList&lt;ObjectA&gt;();
  </code></pre>
  
  <p>and i have this method</p>
  
  <pre><code> private static void createFile() {
      System.out.println("Creating file...");
  
      try {
          FileOutputStream fileOut = new FileOutputStream("file.dat");
          ObjectOutputStream objectOut = new ObjectOutputStream(fileOut);
  
              for (ObjectA o : objectA) {
                  objectOut.writeObject(o); //write the object
              }
  
              objectOut.close(); //then close the writer
  
          }CATCH EXCEPTIONS***************{}
  
  }
  </code></pre>
  
  <p>However i caught this error when trying to run this
  Error on createFile()! java.io.NotSerializableException: ObjectA in the trycatch
  Any ideas?</p>