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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:44:19+00:00 2026-06-08T06:44:19+00:00

i have a weird problem. I am trying to write simple Client – Server

  • 0

i have a weird problem. I am trying to write simple Client – Server app with chat option, but i ran into a problem – Object Input Stream reads wrong class. Error is:

Exception in thread "Thread-4" java.lang.ClassCastException: org.oxomoco.packets.PacketAlive cannot be cast to org.oxomoco.packets.PacketMessage
at org.oxomoco.server.SocketConnectionServer.run(SocketConnectionServer.java:52)
at java.lang.Thread.run(Unknown Source)

And it happens here:

 PacketMessage pm = (PacketMessage)ois.readObject();

Which is in loop that looks like this:

            while(true){




            //if(ois.readObject() instanceof PacketMessage){


            //  pm = (PacketMessage)ois.readObject();
            //  se.println(ois.readObject().toString());
            //}



            if((ois.readObject() instanceof PacketMessage)==true){
                System.out.println("It is: " + (ois.readObject() instanceof PacketMessage));

                PacketMessage pm = (PacketMessage)ois.readObject();

                se.acprintln(">>",uname + ": " +pm.getMsg());

            }
            if((ois.readObject() instanceof PacketAlive)==true){
                System.out.println("-it is: " + (ois.readObject() instanceof PacketAlive));
                PacketAlive pa = (PacketAlive)ois.readObject();
            }

    }

Somehow – even though i check instances – Object input stream is instance of PacketMessage when it should be instance of PacketAlive. Does anyone have an idea why, and of course – how to fix it?

  • 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-08T06:44:21+00:00Added an answer on June 8, 2026 at 6:44 am

    You’re executing

    ois.readObject()
    

    several times, and getting a different object (of a different class?) each time. readObject() pulls each object from the stream, rather than leave it there.

    Instead, read it, assign to a variable and then perform your tests etc. e.g.

    while (true) {
       Object obj = ois.readObject();
       // do something with obj...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this weird problem when trying to INSERT a row into my mysql
I have a bit of a weird problem here! I am trying to write
I have a weird but big problem. I am trying to let the user
I have a weird problem. I create this window, but its blank until i
I have a very weird problem while trying to pass and SQL query using
I have a rather small but weird problem that I can't seem to fix.
I'm trying to work with requirejs and text plugin and I have weird problem.
I have a weird problem on my hand. I am trying to read an
I have a weird problem! I'm trying to create a listview with checkboxes. In
I have some weird problem with templates. When trying to pass a parameterised iterator

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.