Java中使用ObjectInputStream,ObjectOutputStream转递对象的问题 public class YourObject implements Serializable{}你改成 Public class Msg .... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class Server implements Serializable{ class Msg { //.......... }}//.... 搂主的程序有一个问题两个类中Msg类 并不是一个类 反序列化的时候会抛错的其他的地方没有问题 把Msg类改成public类 就没问题了 我的一点建议将公用的message提出来,不要用内部类,应为那时两个不同的对象Message:public class Msg implements java.io.Serializable{ String s1; String s2;}Server:public class Server{ Server() { try { ServerSocket server=new ServerSocket(6666); Socket s=server.accept(); ObjectInputStream ois=new ObjectInputStream(s.getInputStream()); Msg temp=new Msg(); temp=(Msg)ois.readObject(); System.out.println(temp.s1); System.out.println(temp.s2); } catch(Exception e) { System.out.println(e); } } public static void main(String s[]) { new Server(); }}Client:public class Client { Client() { try { Socket s=new Socket("127.0.0.1",6666); ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream()); Msg temp=new Msg(); temp.s2="1"; temp.s2="2"; oos.writeObject(temp); } catch(Exception e) { System.out.println(e); } } public static void main(String s[]) { new Client(); }} client类也要implements Serializable swing 数据库存连接问题 stack overflow求助 急需一个正则表达式(java),只允许显示数字或带有小数点后两位数字的匹配 怎样用 java 取得摄象头的视频? (请指教) 【初级】怎么样正确的使用java中的package??? 请教:多线程中方法前加同步锁的问题 初学者请教大家 一个简单问题 大家说说,实现web打印用那种方案比较好?fop还是applet? java的菜鸟问题 **************Question******************Help me!!!!!!!!!! 在线等 Java 中格式化I/O 是什么?
{
class Msg {
//..........
}
}
//....
两个类中Msg类 并不是一个类 反序列化的时候会抛错的
其他的地方没有问题 把Msg类改成public类 就没问题了
将公用的message提出来,不要用内部类,应为那时两个不同的对象
Message:
public class Msg implements java.io.Serializable{
String s1;
String s2;
}Server:
public class Server
{
Server()
{
try
{
ServerSocket server=new ServerSocket(6666);
Socket s=server.accept();
ObjectInputStream ois=new ObjectInputStream(s.getInputStream());
Msg temp=new Msg();
temp=(Msg)ois.readObject();
System.out.println(temp.s1);
System.out.println(temp.s2);
}
catch(Exception e)
{
System.out.println(e);
}
}
public static void main(String s[])
{
new Server();
}
}
Client:
public class Client {
Client()
{
try
{
Socket s=new Socket("127.0.0.1",6666);
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
Msg temp=new Msg();
temp.s2="1";
temp.s2="2";
oos.writeObject(temp);
}
catch(Exception e)
{
System.out.println(e);
}
}
public static void main(String s[])
{
new Client();
}
}