The file to be read is called "Instructions.ser", and there is a readable text 'serialization.SerializedObject' at the beginning of the file but everything else is serialized. I've read in the serialized file and data, but when I run it, I get an error:
CODE
java.lang.ClassNotFoundException: serialization.SerializedObject
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:289)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:604)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at lab10svang6.Main.main(Main.java:43)
I'm at my wits end trying to find out what the problem is. Can anyone help me? I'm thinking it has to do with the serialization.SerializedObject but am not too sure.
Here is the code:
CODE
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Main
{
public static void main(String[] args)
{
//read file
FileInputStream fis = null;
try
{
//read in file
fis = new FileInputStream("Instructions.ser");
ObjectInputStream input = new ObjectInputStream(fis);
ArrayList<SerializedObject> aliSO = new ArrayList<SerializedObject>();
SerializedObject instruction;
//read data
try
{
while( true )
{
instruction = (SerializedObject) input.readObject();
aliSO.add(instruction);
for( int i = 0; i <= aliSO.size(); i++ )
{
for( SerializedObject so : aliSO )
{
if( i == so.getIntValue() )
{
System.out.print(so);
}
}
}
}
} //end try
//close file
catch( EOFException ex )
{
input.close();
}
}
catch( FileNotFoundException ex )
{
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
System.err.println("File not found.");
}
catch( IOException ex )
{
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
System.err.println("Error opening file.");
}
catch( ClassNotFoundException ex )
{
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
finally
{
try
{
fis.close();
}
catch( IOException ex )
{
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
System.err.println("Error closing file.");
}
}
}
}