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 7967769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:58:29+00:00 2026-06-04T06:58:29+00:00

I’m trying to serialize a class Message from a java server and send them

  • 0

I’m trying to serialize a class Message from a java server and send them to an Android phone.

The phone hangs every time I try to open an ObjectInputStream object, without giving me any errors.

The encoding method –

public void sendMessagesToPhone(String userName) {

    System.out.println("Send messages to phone called");

    ObjectOutputStream outputObjects = null;

    ServerUser user = new ServerUser(userName, "");
    s.getKeys(user);


    user.setMessages();
    ArrayList<Message>  encryptedMessages = user.getMessages();
    try {
        //output = new DataOutputStream(socket.getOutputStream());
        outputObjects = new ObjectOutputStream(socket.getOutputStream());
        outputObjects.flush();

        for(Message m : encryptedMessages) {
            System.out.println(m);
            outputObjects.writeObject(m);


        }
    } catch (Exception e) {
        System.out.println("unable to create the streams");
        e.printStackTrace();
    }

try {
    outputObjects.close();

} catch (Exception e) {
    System.out.println("unable to close the streams");
    e.printStackTrace();
}
}
}

And the attempt to decode on the phone itself –

public void getNewMessages() {

        Socket connect = null;
        ArrayList<Message> incomingMessages = new ArrayList<Message>();
        ObjectInputStream input = null;
        PrintWriter pw = null;

        try {

            connect = new Socket("removed", 7777);
            //hangs here on creating the ObjectInputStream
            input = new ObjectInputStream(connect.getInputStream());
            pw = new PrintWriter(connect.getOutputStream(), true);

            //client parses text input and will respond to the pw input 
            //by calling the sendMessagesToPhone(String user) method
            pw.println("phonemessages");
            pw.println(currentUser.getName());

            Object obj = null;
            while((obj = input.readObject()) != null) {
                if(obj instanceof Message) {
                    incomingMessages.add((Message)obj);
                    }
                else toast = Toast.makeText(this, "object is not a        

    message", Toast.LENGTH_SHORT);
                toast.show();
            }

        } catch(Exception e) {

            toast = Toast.makeText(this, e.getMessage() + "error 1st catch",   

    Toast.LENGTH_SHORT);
            toast.show();
        }
        try {
        pw.close();
        } catch (Exception e) {
            toast = Toast.makeText(this, e.getMessage() + "error 2nd catch", 

    Toast.LENGTH_SHORT);
            toast.show();
        }

        try {
            input.close();

        } catch (Exception e) {
            toast = Toast.makeText(this, e.getMessage() + "error 3rd catch", 

    Toast.LENGTH_SHORT);
            toast.show();
        }

I’m not even sure this is the right approach to be taking, but I’ve found it very difficult to find examples anywhere.

Any helpful direction would be much appreciated.

  • 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-06-04T06:58:30+00:00Added an answer on June 4, 2026 at 6:58 am

    Could be that serialized object are from different packages – this should throw a class not found exception. Here is some more info. I have not found a solution other than making a common package or some custom mapping.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.