powered by Jive Software

Question of Smack4.2

i am new to smack4.2, i want to write a demo of smack4.2 to connect my own server, but it shows me the errors, can anyone can help me?

code:

XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();

config.setHost(“127.0.0.1”);

config.setPort(5222);

DomainBareJid serviceName = JidCreate.domainBareFrom("test1@127.0.0.1") ;

config.setServiceName(serviceName);

config.setHostAddress(InetAddress.getByName(“127.0.0.1”));

config.setUsernameAndPassword(“test1”, “test1”);

config.setSecurityMode(XMPPTCPConnectionConfiguration.SecurityMode.disabled);

XMPPTCPConnection xmppCon = new XMPPTCPConnection(config.build());

xmppCon.connect();

xmppCon.login();

error msg:

Exception in thread “main” java.lang.NullPointerException

at org.jivesoftware.smack.util.stringencoder.Base64.encode(Base64.java:64)

at org.jivesoftware.smack.util.stringencoder.Base64.encode(Base64.java:60)

at org.jivesoftware.smack.util.stringencoder.Base64.encodeToString(Base64.java:42)

at org.jivesoftware.smackx.caps.EntityCapsManager.generateVerificationString(Entit yCapsManager.java:723)

at org.jivesoftware.smackx.caps.EntityCapsManager.generateVerificationString(Entit yCapsManager.java:589)

at org.jivesoftware.smackx.caps.EntityCapsManager.updateLocalEntityCaps(EntityCaps Manager.java:485)

at org.jivesoftware.smackx.caps.EntityCapsManager.(EntityCapsManager.java:31 3)

at org.jivesoftware.smackx.caps.EntityCapsManager.getInstanceFor(EntityCapsManager .java:376)

at org.jivesoftware.smackx.caps.EntityCapsManager$1.connectionCreated(EntityCapsMa nager.java:119)

at org.jivesoftware.smack.AbstractXMPPConnection.(AbstractXMPPConnection.jav a:304)

at org.jivesoftware.smack.tcp.XMPPTCPConnection.(XMPPTCPConnection.java:306)

in class org.jivesoftware.smack.util.stringencoder.Base64

method

public static final byte[] encode(byte[] input, int offset, int len) {

return base64encoder.encode(input, offset, len);

}

raises an NPE, because static field

private static Base64.Encoder base64encoder;

is not initialized

So how to fix it

seems to be an answer for this issue java - XMPP client using Smack 4.1 giving NullPointerException during login - Stack Overflow

I have same question. but now I had resolve. you need add smack-java7 dependence.