title: Getting a java.io.InvalidClassException when trying to save and read a file
body: <pre><code>public static void save(Settings settings) {
      try {
          ObjectOutputStream os = 
                  new ObjectOutputStream(
                          new FileOutputStream(settingsFile));
          os.writeObject(settings);
          os.close();
      } catch(Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>This is the code that saves a class     Settings    to a file.</p>
  
  <pre><code>public static Settings load() {
      try {
          ObjectInputStream is = 
                  new ObjectInputStream(
                          new FileInputStream(settingsFile));
          Settings settings = (Settings) is.readObject();
          is.close();
          return settings;
      } catch(Exception e) {
          e.printStackTrace();
      }
      return null;
  }
  </code></pre>
  
  <p>This code will read the file and return the     Object     which is cast to     Settings    </p>
  
  <p>The error is get is at</p>
  
  <pre><code>Settings settings = (Settings) is.readObject();    
  </code></pre>
  
  <p>and the StackTrace is </p>
  
  <pre><code>java.io.InvalidClassException: com.Settings; local class incompatible: stream classdesc serialVersionUID = 5215625451621355973, local class serialVersionUID = -6263468811172060812
  at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
  at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
  at java.io.ObjectInputStream.readClassDesc(Unknown Source)
  at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
  at java.io.ObjectInputStream.readObject0(Unknown Source)
  at java.io.ObjectInputStream.readObject(Unknown Source)
  at com.Settings.load(Settings.java:51)
  at com.Main.main(Main.java:23)
  </code></pre>
  
  <p>Im not entirely sure why I am getting this error because the object that is written to the file is Settings and the object that is being read is also Settings. Any help would be greatly appreciated</p>