ObjectInputStream readObject(): ClassNotFoundException

前端 未结 2 1308
醉话见心
醉话见心 2021-01-20 03:20

In both client and server classes, I have an exact same inner class called Data. This Data object is being sent from the server using:

ObjectOutputStream out         


        
2条回答
  •  死守一世寂寞
    2021-01-20 03:51

    What you were trying to do is something along the lines of the following:

    class TCPServer {
        /* some code */
    
        class Data {
    
        }
    }
    
    class TCPClient {
        /* some code */
    
        class Data {
    
        }
    }
    

    Then you are serializing a TCPServer$Data and trying to unserialize it as a TCPClient$Data. Instead you are going to want to be doing this:

    class TCPServer {
        /* some code */
    
    }
    
    class TCPClient {
        /* some code */
    
    }
    
    class Data {
        /* some code */
    
    }
    

    Then make sure the Data class is available to both the client and the server programs.

提交回复
热议问题