Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6794867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:16:25+00:00 2026-05-26T18:16:25+00:00

I am writing an app that makes use of Object Output and Input Streams.

  • 0

I am writing an app that makes use of Object Output and Input Streams. However I have a problem, because I am not able to send my object properly. I write it to stream, and server gives me a class not found exception, even though both client and server have exactly the same copy of this class (the only difference is the package name) with the same serial id. Here is my class:

import java.io.Serializable;

public class Message implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = 1L;
private String username = null;
private String hashedPassword = null;
private Integer code = null;
private String from = null;
private String to = null;
private Object data = null;

public Message() {

}

public Message(Integer code) {
    this.code = code;
}

public Message(Integer code, Object data) {
    this.code = code;
    this.data = data;
}

public Message(String username, String hashedPassword, Integer code,
        String from, String to, Object data) {
    this.username = username;
    this.hashedPassword = hashedPassword;
    this.code = code;
    this.from = from;
    this.to = to;
    this.data = data;
}

public Integer getCode() {
    return code;
}
    //other getters and setters
}

That is the class which object i want to send. Here is the client code:

(It is wirtten just for testing)

public static void main(String[] args) {
        try {
            Socket s = new Socket("localhost", 5656);
            ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());

            Message m = new Message("user3", "123", 100, "2011-06-11 22:22:22",
                "2011-06-11 22:22:22", "test");
        oos.writeObject(m);
        oos.flush();


        ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
        Message n = (Message) ois.readObject();
        System.out.print(n.toString());

        oos.close();
        ois.close();

    } catch (Exception e) {
        e.printStackTrace();
    }

and here is part of server code (yes it is multithreaded):

package systemZarzadzaniaReporterami.serwer;

import java.beans.ExceptionListener;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.sql.SQLException;

public class ClientHandler extends Thread {

private ExceptionListener exceptionListener;

private Socket socket;
private String ip;

public ClientHandler(ExceptionListener exceptionListener, Socket socket) {
    this.exceptionListener = exceptionListener;
    this.socket = socket;
    ip = socket.getInetAddress().getHostAddress();
}

public void run() {
    Message in = null;
    ObjectInputStream inputStream = null;
    ObjectOutputStream outputStream = null;

    try {
    //  ClientListener.CONNECTION_COUNTER++;

        inputStream = new ObjectInputStream(socket.getInputStream());

        in = (Message) inputStream.readObject();
        MessageProcessor messageProcessor = new MessageProcessor();

        System.out.print(in.getUsername());

        outputStream = new ObjectOutputStream(socket.getOutputStream());

        Message out = messageProcessor.process(in, ip);
                System.out.print(in.getCode().toString());      
        outputStream.writeObject(out);
        outputStream.flush();
    } catch (IOException e) {
        e.printStackTrace();
        exceptionListener.exceptionThrown(new ServerException(Codes.ERR_CONNECTION_ERROR));
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
        exceptionListener.exceptionThrown(new ServerException(Codes.ERR_MYSQL_ERROR));
    } finally {
        if (inputStream != null)
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
                exceptionListener.exceptionThrown(new ServerException(Codes.ERR_CONNECTION_ERROR));
            }
        if (outputStream != null)
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
                exceptionListener.exceptionThrown(new ServerException(Codes.ERR_CONNECTION_ERROR));
            }
        if (socket != null)
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
                exceptionListener.exceptionThrown(new ServerException(Codes.ERR_CONNECTION_ERROR));
            }
    //  ClientListener.CONNECTION_COUNTER--;
    }
}

}

I am pretty confused now. Because I have no idea why is such thing happening.

What is most important in my opinion that the following code does well when I replace Message with string.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:16:26+00:00Added an answer on May 26, 2026 at 6:16 pm

    the only difference is the package name

    That won’t work. The class name (including the package name) must be the same on both sides.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a Boxee app that makes use of YouTube videos and I want
I'm writing an app that makes use of the fileobserver in android. When I
Hello I am writing an app that makes the use of coordinates from a
i'm writing an app that needs a calculation support (Fun project). However, is there
I am writing an app that uses the TimeSpan object. Specifically I am using
We are writing an app that will use T4 to generate Flex/Actionscript to compile
I'm working on an MVC app that makes heavy use of Services. My question
I'm writing an app in monotouch which also makes use of a C++ library,
I am writing an app that may have in its memory quite a bit
I have a few files in \AppData\Roaming that my app is writing to. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.