I am trying to use Smack 4.1.0-rc3 for implementing a java xmpp client which connects to a ejabberd xmpp server. I am using the following code for connecting to the server.
XMPPTCPConnectionConfiguration connConfig = XMPPTCPConnectionConfiguration
.builder()
.setServiceName("example.com")
.setHost("192.168.56.101")
.setPort(5222)
.setCompressionEnabled(false)
.setSecurityMode(SecurityMode.disabled)
.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
})
.setUsernameAndPassword(user, pass).build();
connection = new XMPPTCPConnection(connConfig);
connection.connect();
connection.login();
While executing the 'connection.login()' i am getting the following NullPointerException.
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.smack.sasl.SASLMechanism.authenticate(SASLMechanism.java:199)
at org.jivesoftware.smack.sasl.SASLMechanism.authenticate(SASLMechanism.java:169)
at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:236)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.loginNonAnonymously(XMPPTCPConnection.java:365)
at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:452)
at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:410)
at org.org.oodlezz.unio.jabber.client.XmppClient.connect(XmppClient.java:88)
at org.org.oodlezz.unio.jabber.client.Client.main(Client.java:32)
Am I doing something wrong in the code? Can you please point me towards a proper example for using Smack 4.1.0-rc3?
The other answers on this page have parts of the answer, but trying them I figured out what is really missing is the dependency on smack-java7 library. Adding this dependency causes the initializers to be called, the base64encoder to be set, and so this NullPointerException disappears.
On Android, replace smack-java7 with smack-android.