Java - 使用ObjectInputStream和ArrayList时的ClassNotFound异常

时间:2014-08-12 20:38:57

标签: java arraylist objectinputstream objectoutputstream

我试图将ArrayList的内容从客户端移动到服务器。尝试readObject()时,我收到一个ClassNotFoundException输入。这是我的代码,以及堆栈跟踪:

客户:

 ArrayList<Person> people = new ArrayList<Person>();
 ObjectOutputStream output = new ObjectOutputStream(socket.getOutputStream());
 for (Person p : people) {
    output.writeObject(p);
 }

服务器:

 ArrayList<Employee> employees = new ArrayList<Employee>();
 ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
 employees = (ArrayList<Employee>) input.readObject(); //Line 47

来自服务器的错误:

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)

0 个答案:

没有答案