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:

connected

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(XMPPTCPConnect ion.java:365)**

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

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

** at Test.main(Test.java:29)**

Here’s a preview of my codes:

XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration

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

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

** .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 https://www.igniterealtime.org/builds/smack/docs/latest/documentation/ 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