Problem with ConnectionListener


I add ConnectionListener like this :

ConnectionListener cn = new ConnectionListener(){

public void connectionClosedOnError(Exception e){

System.out.println("Error "+e.getLocalizedMessage());


reconnect(5, userr, pass,5);

} catch(InterruptedException ie){

for(int i = 0; i < vector.size(); i++){

vector.elementAt(i).errorNotification(getName(), "Interrupted: "

  • getMessageForCode(e.toString()));




public void connectionClosed(){





and I still have exceptions like Connection reset

Am I doing something wrong?


Yes that’'s wrong

ConnectionListener is a java interface, it is not newed, it is implemented by your object.

example snippet

public class receiver implements ConnectionListener, PacketListener


private XMPPConnection xmppCon; // The connection to the XMPP server

private String jabberServer = “sdooley”;

private String jabberUser = “receiver”;

private String jabberPassword = “receiver”;

private int msgnum = 0;

public receiver ()




System.out.println ("Connecting to server: " + this.jabberServer);

this.xmppCon = new XMPPConnection (this.jabberServer);

this.xmppCon.addConnectionListener (this);


// more code


// Implementation of ConnectionListener requires these methods

public void connectionClosed ()


System.out.println ("Closing? " + this.xmppCon.getUser () +

" connected: " + this.xmppCon.isConnected ());



By implementing an interface you provide the methods defined for the interface.


I think you misunderstood his code (probably due to the absence of the -tags). He’'s creating an inner class using this construct.

thanks for understanding

And by the way I’'m a girl :stuck_out_tongue:

And still waiting for help


What is your reconnect code doing?



I’‘m sorry for the gender misconception, it wasn’'t really obvious from your nick

What’'s the stack trace of the exception?