Question

Possible Duplicate:
StreamCorruptedException: invalid type code: AC

Hello guys I am trying to read object from the stream over the network... I am using ReadInputObject method ... and I am implementing it inside a thread to recieve the data ... here is the while loop in the thread

while((dp = (DataPackage) ois.readObject()) != null)
        {

             Ball b = new Ball();
             b.setX(dp.x);
             b.setY(dp.y);
             jTextField1.setText(b.getX() + "    " +b.getY());
             b.paint(ob.getGraphics());
             b.setVisible(true);
             ois.reset();

        }
    } catch (IOException ex) {
        System.out.println("Error 1 is Here");
    } catch (ClassNotFoundException ex) {
        System.out.println("Error 2 is here");
    }  

the problem is that the ois gets the first object and then .... it goes inside the exception and prints out this Error 1 is here

here is the code where I send the object

DataPackage dp = new DataPackage();
    dp.x=b1.getX();
    dp.y=b1.getY();
    dp.t=b1.getT();
    dp.dx=(int)b1.getDx();
    dp.dy=(int)b1.getDy();

    ObjectOutputStream oos = null;
    try {
        oos = new ObjectOutputStream(Server_login.client.getOutputStream());
    } catch (IOException ex) {
        Logger.getLogger(Game_Painters_right.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        oos.writeObject(dp);
    } catch (IOException ex) {
        Logger.getLogger(Game_Painters_right.class.getName()).log(Level.SEVERE, null, ex);
    }

what is the wrong in my code ?? thank you

Was it helpful?

Solution

Well, remove the call to ois.reset(). Why is it there in the first place?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top