简体   繁体   中英

Class error whilst reconstructing a serialized object

I have two programs, HunterClient and HunterServer

Both Programs have a main class and a Message class. The message class is an exact copy other than one is within the HunterClient project and one is in the HunterServer project. (both have a project deceleration within the class)

This is how I send the first object through the Client

String str = scanner.next();
//Send down Stream
out.writeObject(new Message(str));
out.flush();

This is how I receive the object at the other end

try {
 Message message = (Message) in.readObject();
 } catch (Exception ex) {
            System.out.println("err... " + ex);
        }

However running this and trying to send a message from the client to the server I get the following error message.

err... java.lang.ClassNotFoundException: hunterclient.Message

That message is received on HunterMessenger not HunterClient. Both programs are built as netbeans projects... The way im understanding this error is that the program is looking for the hunterclient class in the huntermessenger program... how can I make it use its native messenger class?

These are my two message classes

The Server

package huntermessenger;

import java.io.Serializable;

public class Message implements Serializable{

private String message;

public Message(String message) {
    this.message = message;
}

public String getMessage(){
    return message;
}
}

The Client

package hunterclient;

import java.io.Serializable;

public class Message implements Serializable{

private String message;

public Message(String message) {
    this.message = message;
}

public String getMessage(){
    return message;
}
}

您使HunterClient类可序列化了吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM