0

I am having a weird issue of not being able to cast a packet into a message. I get an error at this line: Message msg = (Message) arg0; It says

"Cannot cast from Packet to Message"

//Code

     connection.connect();
     connection.login(uN, pw);

    PacketTypeFilter filter = new PacketTypeFilter(Message.class);
    PacketCollector myCollector = connection.createPacketCollector(filter);
    PacketListener myListener = new PacketListener(){

            @Override
            public void processPacket(Packet arg0) {
                // TODO Auto-generated method stub
                if(arg0 instanceof org.jivesoftware.smack.packet.Message){
                        Message msg = (Message) arg0;
                        }
                    }

                };
    connection.addPacketListener(myListener, filter);
Balanivash
  • 6,709
  • 9
  • 32
  • 48
Kelley
  • 1
  • 1

1 Answers1

2

I am going to guess that since you have Message fully qualified in the check for instanceof but not in the line with your cast, that the Message used in your cast is not the correct Message class.

Check your imports and see what Message you have there, it is probably not org.jivesoftware.smack.packet.Message.

Robin
  • 24,062
  • 5
  • 49
  • 58
  • can you please look over this i specified the above package but not able to get the `Message` packet in `pubsub` `http://stackoverflow.com/questions/13777234/read-incoming-message-packets-in-pubsub-using-smack` – Hunt Dec 18 '12 at 08:45