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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:12:01+00:00 2026-05-27T16:12:01+00:00

Hi guys I am getting this problem on my console, but only appear sometimes..

  • 0

Hi guys I am getting this problem on my console, but only appear sometimes.. not always..
I would like your help if possible, thanks

Error:

Exception in thread "Thread-2" java.lang.ClassCastException: cannot assign instance of java.lang.String to field Element.posElement of type java.awt.Point in instance of Personagem
    at java.io.ObjectStreamClass$FieldReflector.setObjFieldValues(Unknown Source)
    at java.io.ObjectStreamClass.setObjFieldValues(Unknown Source)
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readArray(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readArray(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    at LaunchCliente$receberDoServidor.run(LaunchCliente.java:332)

and here is my code, when I am trying to read the object :

Object a = inputStream.readObject();


if(a instanceof Mapa){
    Mapa novo = (Mapa) a;
    if(launchJogo.getListaObstaculos().size() == 0)
    launchJogo.setLista(novo.getListaObstaculos());
    launchJogo.setListaPers(novo.getListaPersonagens());
    launchJogo.setElements(novo.getElements());
    launchJogo.getFrame().pack();
}
else if(a instanceof logout){
    if(launchJogo != null)
    launchJogo.getFrame().dispose();
    novo.close();
}
else if(a instanceof updateList){
    Vector<String> novo = ((updateList) a).getUpdateList();
    if(novo.size() != 0){
        if(!nomeUtilizador.isEnabled()){
            modeloDaLista.clear();
            arrayDeJogos = new Vector&lt;String&gt;(novo);
            for (String x : arrayDeJogos) {
                modeloDaLista.addElement(x);
            }
            janela.validate();
        }
    }
    if(novo.size() == 0){
        modeloDaLista.clear();
    }
}
else if(a instanceof String){
    String b = a.toString();
    if(b.equals("COLOR:FALSE")){
        JOptionPane.showMessageDialog(c, "Essa cor já está em uso no jogo selecionado!" , "Cor já escolhida!",
        JOptionPane.WARNING_MESSAGE);
        launchJogo = null;
        cores.dispose();
        janela.setVisible(true);
    }
    else if(b.equals("CREATE:BUTTONSTART")){
        launchJogo.getOptions().showButton(true);
    }
    else if(b.equals("ACTIVE:BUTTONSTART")){
        if(!launchJogo.getOptions().isButtonEnabled()){
            launchJogo.getOptions().setBotaoState(true);
        }
    }
    else if(b.equals("COLOR:TRUE")){
        cores.dispose();
        out.writeObject(new addToAGame(corDoJogador, nomeJogador, jogoSelecionado));
        launchJogo = new LaunchJogo(launchCliente, jogoSelecionado, nomeJogador);
    }
    else if(b.equals("LAUNCH:GAME")){
        if(launchJogo != null)
        launchJogo.addPersonagemListener();
    }
}
} catch (ClassNotFoundException e) {
  System.out.println("Class not found!");
} catch (IOException e) {
  this.interrupt();
}

Thanks alot in advance guys, I would appreciate some help

  • 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-27T16:12:01+00:00Added an answer on May 27, 2026 at 4:12 pm

    The error message is telling you that the object stream is encountering a runtime error while rebuilding a serialized object. The object state being deserialized has a String for a value of the field Element.posElement … which ought to be a Point according to the version of the Element class that your application is using.

    The problem is with the actual serialized objects that you are attempting to read. I suspect that some time in the past you have changed the type of the Element.posElement field from String to Point (or vice versa), and you are trying to deserialize an object created by the other version of the class to the one you are currently using.

    Normally, the object reader would complain about incompatible versions, but I suspect that you have:
    – added serialVersionId constants to your classes, and
    – failed to update the serialVersionId for Element after making a change that makes the new version incompatible with the old one.


    Another possibility (see @TInusTate’s comment) is that there are multiple threads writing to a shared ObjectOutputStream instance without synchronizing properly. This can result in the bytes from different objects getting “mixed up”.

    You could get a similar effect if you did other things like:

    • Multiple ObjectOutputStream instances wrapping a shared OutputStream.
    • Multiple threads reading from the same ObjectInputStream.

    In some cases, the solution is proper synchronization. In others, the problem is intractable. None of the stream classes are inherently thread-safe, and multiple threads multiplexing data over a single stream is a difficult problem, requiring considerable care.


    You are going to need to find where these incompatible serialized objects are coming from and either get rid of them or (somehow) replace them. In the future, you need to be more careful whan making changes to classes that may have been serialized and persisted, etcetera.

    (This kind of problem is one of the reasons why ObjectStream serialization can be problematic for persisting state.)

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

Sidebar

Related Questions

Guys i need some help here , im getting this error here at the
NOTE: THE PROBLEM IS NOT IN THIS CODE, BUT THE ANSWER FOR EXC_BAD_ACCESS is
Hey guys. This is a very simple question, I'm sure, but I'm getting myself
Thus far you guys have been wildly helpful with me getting this little ditty
Guys, I've came across this problem I can't resolve myselg, I'm pretty sure I
I hope this isn't too vague, but I'm stuck on a problem that has
Hey guys, hoping for some help with this :( been stuck on it for
Hey guys! I'm getting a problem that is driving me crazy. I defined an
Guys, I'm havin a problem with this... My User class has a property UserType
My problem is about putting and getting variables into/from the play scope. It's not

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.