|
100鱼币
我用java网络流传对象,结果运行的时候报错,度娘后感觉自己也没有写错,希望鱼C的大神能帮我一下@小甲鱼 @零度非安全
运行后在服务器端的 im i = (im)ois.readObject(); 这行报的错为:java.lang.ClassNotFoundException:
我粘贴下部分代码
这是我要传输的对象
public class im implements java.io.Serializable{
int x,y;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
这是客户端
public Test2(){
try {
im i = new im();
i.x = 2;
i.y = 3;
Socket s = new Socket("127.0.0.1",9999);
ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
oos.writeObject(i);
oos.flush();
oos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
这是服务器端
public Test1(){
try {
ServerSocket ss = new ServerSocket(9999);
Socket s = ss.accept();
ObjectInputStream ois=new ObjectInputStream(s.getInputStream());
im i = (im)ois.readObject();
System.out.println("x="+i.x+" y="+i.y);
ois.close();
} catch (Exception e) {
e.printStackTrace();
}
}
|
最佳答案
查看完整内容
类没找到,你看下你classpath路径是否配置了?注意末尾的“”;.;“”,若在IDE下,看下有没有导入相应的包?
|