Take the 2-minute tour ×

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"


     connection.login(uN, pw);

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

            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);
share|improve this question
add comment

1 Answer

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.

share|improve this answer
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-pu‌​bsub-using-smack –  Hunt Dec 18 '12 at 8:45
add comment

Your Answer


