请教老师一个问题

来源:-

iwuhao

2015-03-07 01:06


我在客户端中这么写

socket = new Socket(ip, 23456);

oos = new ObjectOutputStream(socket.getOutputStream());

oos.writeObject(transfer);

oos.flush();

服务器端学老师这么写

ois = new ObjectInputStream(socket.getInputStream());

CammandTransfer transfer = (CammandTransfer) ois.readObject();

但是出现了这种错误

java.lang.ClassNotFoundException: com.android.yunnotes.CammandTransfer

at java.net.URLClassLoader$1.run(URLClassLoader.java:372)

at java.net.URLClassLoader$1.run(URLClassLoader.java:361)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:360)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:340)

at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:626)

at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1613)

at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)

at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)

at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)

at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)

at com.myserver.main.ServerThread.run(ServerThread.java:23)

23行就是那句CammandTransfer transfer = (CammandTransfer) ois.readObject();

这是什么问题呢


补充com.android.yunnotes是客户端的包,com.myserver.main是服务器的包

写回答 关注

1回答

  • iwuhao
    2015-03-07 21:45:04

    我已经找到问题了

Java Socket应用---通信是这样练成的

分享的是 Java 中的网络编程,使用Socket实现网络聊天通信

125013 学习 · 590 问题

查看课程

相似问题