Question

I am trying to create new user in XMPP using java but i am getting Null Pointer exception. can some body help me for this.

I have tried

            this.ConnectionConfiguration connConfig = new 
            ConnectionConfiguration("Serverip", 5222);
            XMPPConnection connection = new XMPPConnection(connConfig);
            connection.login("admin@target.com", "kjbkishan");
            connection.connect();

            AccountManager accountManager = connection.getAccountManager();
            Map<String, String> attributes = new HashMap<String, String>();
            attributes.put("username", "krishna");
            attributes.put("password", "123456");
            attributes.put("email", "krishna@gmail.com");
            attributes.put("name", "krishnathakkar");

            accountManager.createAccount("krishna@target.local", "123456",attributes);

            Registration registration = new Registration();
            registration.setType(IQ.Type.SET);
            registration.setTo(connection.getServiceName());

            PacketFilter filter = new AndFilter(new PacketIDFilter(registration.getPacketID()), new PacketTypeFilter(IQ.class));
            PacketCollector collector = connection.createPacketCollector(filter);
            connection.sendPacket(registration);

            connection.connect();

any help will be appreciated.

stacktrace

java.lang.IllegalStateException: Not connected to server.
    at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:382)
    at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:349)
    at com.verve.XMPPUSer.UserCreating.commectxmpp(UserCreating.java:37)
    at com.verve.XMPPUSer.UserCreating.main(UserCreating.java:27
Was it helpful?

Solution

Well here the simple answer.

            ConnectionConfiguration connConfig = new ConnectionConfiguration("ip", 5222);
            XMPPConnection connection = new XMPPConnection(connConfig);

            connection.connect();
            connection.login("username", "password");
            AccountManager accountManager = connection.getAccountManager();
            accountManager.createAccount("adminCreated1", "123456");
            connection.disconnect();

its done.. :D

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top