public class YourObject implements Serializable{
}
你改成 Public class Msg ....

解决方案 »

  1.   

    public class Server  implements Serializable
    {
      class Msg {
      //..........
      }
    }
    //....
      

  2.   

    搂主的程序有一个问题
    两个类中Msg类  并不是一个类  反序列化的时候会抛错的
    其他的地方没有问题  把Msg类改成public类  就没问题了
      

  3.   

    我的一点建议
    将公用的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();
       }
    }
      

  4.   

    client类也要implements Serializable