问题
I'm trying to move the contents of an ArrayList from the client to the server. When trying to readObject() the input I receive a ClassNotFoundException. Here is my code, along with the stack trace:
Client:
ArrayList<Person> people = new ArrayList<Person>();
ObjectOutputStream output = new ObjectOutputStream(socket.getOutputStream());
for (Person p : people) {
output.writeObject(p);
}
Server:
ArrayList<Employee> employees = new ArrayList<Employee>();
ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
employees = (ArrayList<Employee>) input.readObject(); //Line 47
Error from server:
java.lang.ClassNotFoundException: Person
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.readObject(Unknown Source)
at Server.<init>(Server.java:47)
at ServerGUI.main(ServerGUI.java:143)
来源:https://stackoverflow.com/questions/25273658/java-classnotfound-exception-when-working-with-objectinputstream-and-arraylist