powered by Jive Software

Help with creating a new user

Hello,

Im using Smack for the first time and i have come up with a problem. When I try to register a new user I get a no server response and I can’t seem to find the problem. Could somebody help me?

this is my code for creating a new user

/

public *boolean *register(String userId, String password) {

this.userId= userId;

this.password= password;

try {

AccountManager accountManager = connection.getAccountManager();

accountManager.createAccount(userId, password);

System.out.println(“Account for” + userId + “successful”);

return true;

} catch (XMPPException e) {

System.out.println(“Could not create account” + e);

e.printStackTrace();

}

return false;

} /

and this is part of the code im trying to use to actually register

/

if (e.getSource() == registerButton) {

if (mconnection.isConnected()){

mconnection.register(getUsername(), getPassword());

System.out.println(getUsername());

JOptionPane.showMessageDialog(null, "Account for "

  • getUsername() + " has been created");

} else {

JOptionPane.showMessageDialog(null, "Account for "

  • getUsername() + " could not be created !");

}

}}

What am I doing wrong?

/

Hi george23,

What type of class is your mconnection object? Is it of type XMPPConnection? If so, I’m surprised your code even compiles because there is no register() method for that class. Instead you’ll want to use the login() method.

Hope that helps,

Ryan

Hi Ryang,

well the boolean register method is an Interface method that was given and which we are supposed to implement. And what I’m doing is creating an account in this method. And yes it is an XMPP Connection. Don’t now why my code’s not working.:0

Thanks

Your code seems correct, at least that is the same code I use to create accounts with Smack. My guess is that it is something else…a few things to check:

1.) What you are passing in as the userId? It should be just the user portion of the JID, without a domain.

2.) Does your server support new account registration? Some servers have a property set to disable that feature.

3.) Are you sure your connection is established before trying to create the account?

Chris

Hi george23,

Ah, I didn’t realize you had included your registration code; you might want to use the tag in the future so your formatting stays straight.

It looks like the code you’ve posted is ok so I would guess there is a problem somewhere else in your application. Have you started up the Smack debugger to look at the traffic between your application and server?

Thanks,

Ryan

Heh, looks like Chris beat me to the punch with some good suggestions.

Hi Chris,

Well its not a problem with the userID cos I dont’t add the domain , neither is it aproblem with the server cos it supprts account creation. So it must have something to do with establishing a connection. This is what I’ve done now

////////////

try {

connection = new XMPPConnection(“server site”);

connection.connect();

AccountManager accountManager = connection.getAccountManager();

accountManager.createAccount(userId, password);

System.out.println(“Account for” + userId + “successful”);

return true;

} catch (XMPPException e) {

System.out.println(“Could not create account” + e);

e.printStackTrace();

}

return false;

}

////////////////

I’m still getting the same no response from server problem,aaaaaaaaaaargh