The problem is likely the ToContainsFilter on con.getConnectionID(). What are you trying to do there? The server will only send messages that are addressed to you, and I think you misunderstand what the connection ID is used for (it’'s not really that useful of a thing at all, really).
As you told me by email you are trying to receive messages that were sent to you while you were offline. Your code snippet looks good but since I don’'t have your whole code I think that may be the problem is that you are finishing the “program” too soon so you cannot receive the stored messages.
You can try the following code which is very similar to your code but adds some delays at the end so you can get some time in order to recieve the messages before you close the connection (by ending your program). In a real application you won’‘t need those delays since the application won’'t disconnect after the login.
XMPPConnection con = new XMPPConnection(host, port);
con.login(username, password, resource);
PacketFilter filter = new PacketTypeFilter(Message.class);
PacketListener list = new PacketListener() {
public void processPacket(Packet packet) {
Message message = (Message)packet;
System.out.println(message);
}};
con.addPacketListener(list, filter);
Thread.sleep(500);
System.out.println("Waiting");
Thread.sleep(500);
System.out.println("The end");