Smack 4.1.1 NullPointerException After Login

I’ve already setup a XMPP server (ejabberd) and able to connect to it.

I’m doing testing on Eclipse IDE 1st before starting development on Android platforms.

But every time I try to do a login, the system will prompt the following error:


Exception in thread “main” java.lang.NullPointerException

** at org.jivesoftware.smack.util.stringencoder.Base64.encode(**

** at org.jivesoftware.smack.util.stringencoder.Base64.encode(**

** at org.jivesoftware.smack.util.stringencoder.Base64.encodeToString(**

** at org.jivesoftware.smack.sasl.SASLMechanism.authenticate(**

** at org.jivesoftware.smack.sasl.SASLMechanism.authenticate(**

** at org.jivesoftware.smack.SASLAuthentication.authenticate( 236)**

** at org.jivesoftware.smack.tcp.XMPPTCPConnection.loginNonAnonymously(XMPPTCPConnect**

** at org.jivesoftware.smack.AbstractXMPPConnection.login( :452)**

** at org.jivesoftware.smack.AbstractXMPPConnection.login( :410)**

** at Test.main(**

Here’s a preview of my codes:

XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration

** .builder().setUsernameAndPassword(“admin”, “password”)**

** .setServiceName(“localhost”).setHost(“”)**

** .setPort(5222).setSecurityMode(SecurityMode.disabled)**

** .allowEmptyOrNullUsernames().build();**

** XMPPTCPConnection connection = new XMPPTCPConnection(config);**

** connection.connect();**

** if (connection.isConnected()) {**

** System.out.println(“connected”);**

** }**

** connection.login();**

I did read up a bit on SASL and stuffs, but still unsure on how I can get around this.

P.S. I noticed that the documentation here seems to be outdated? By any chance it will be updated soon?

How did you add Smack to your project? Did you read the Readme?

Hello Flow,

I imported the Smack libraries into the project by adding them to the java build path.

Initially no, but I did already. A thing to note, many thanks.

My issue seems that not all required libraries were imported based on the target platform, got it resolved.

Reference: Smack 4.1 Readme and Upgrade Guide · igniterealtime/Smack Wiki · GitHub