title: Java SerialIzation: 'ClassNotFoundException' when deserializing an Object
body: <p>The error:</p>
  
  <blockquote>
    <p>java.lang.ClassNotFoundException: testprocedure.tp$3
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at java.io.ObjectInputStream.resolveClass(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.defaultReadFields(Unknown Source)
        at java.io.ObjectInputStream.readSerialData(Unknown Source)
        at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
        at java.io.ObjectInputStream.readObject0(Unknown Source)
        at java.io.ObjectInputStream.readObject(Unknown Source)
        at core.ProcedureSetup.load(ProcedureSetup.java:57)
      at core.Engine.main(Engine.java:25)</p>
  </blockquote>
  
  <p>I instantiate the object and call the "ProcedureSetup"'s "save" method from Class "tp".</p>
  
  <pre><code>ProcedureSetup ps=new ProcedureSetup(new Procedure(){ public void doStuff(){ System.out.println("Stuff is being done"); }});
  ps.save();
  </code></pre>
  
  <p>however I load from a different collection of programs that has -ALL- required code but "tp"</p>
  
  <pre><code>ProcedureSetup ps=new ProcedureSetup();
  ps.load();
  </code></pre>
  
  <p>Object saving and loading within class:</p>
  
  <pre><code>public void load(){
      String path=Operator.persistentGetFile();//gets the file path
      ObjectInputStream ois=null;
      FileInputStream fin=null;
      ProcedureSetup temp=null;
      try {
          fin = new FileInputStream(path);
          ois = new ObjectInputStream(fin);
          temp=(ProcedureSetup) ois.readObject();
          ois.close();
          fin.close();
      } catch (IOException e) {
          e.printStackTrace();
      } catch (ClassNotFoundException e) {
          e.printStackTrace();
      }
  
      if(ois!=null){
          try {
              ois.close();
          } catch (IOException e) {}
      }
      if(fin!=null){
          try {
              fin.close();
          } catch (IOException e) {}
      }
      if(temp!=null){
          a=temp.a;
      }else{
          load();//If a load is failed, restart process.
      }
  }
  
  public void save(){
      String path=Operator.persistentGetDirectory();//get directory to save to
          String input =  JOptionPane.showInputDialog(this, "Enter the File name:");
          ObjectOutputStream oos=null;
          FileOutputStream fon=null;
          try {
              fon = new FileOutputStream(path+input+".obj");
              oos = new ObjectOutputStream(fon);
              try {
                  oos.writeObject(this);
              } catch (CloneNotSupportedException e) {
                  e.printStackTrace();
              }
              oos.close();
              fon.close();
          } catch (IOException e) {
              e.printStackTrace();
          }
              if(oos!=null){
          try {
              oos.close();
          } catch (IOException e) {}
      }
      if(fon!=null){
          try {
              fon.close();
          } catch (IOException e) {}
      }
  
  }
  </code></pre>
  
  <p>My questions are:</p>
  
  <p>Why are these errors happening?</p>
  
  <p>Why (if necessary) do I need to have "tp" in my classpath?</p>
  
  <p>If there is in fact a way to save the object in its current state with out the necessity of "tp" in the classpath how would I go about doing that? (Links would be lovely)</p>