Smack 4.4.8 Base64Encoder problem

Hello , i am using smack 4.4.8 as a openfire client. When I try to make login its shows this error.

java.lang.NullPointerException: Cannot invoke "org.jivesoftware.smack.util.stringencoder.Base64$Encoder.encodeToString(byte[])" because "org.jivesoftware.smack.util.stringencoder.Base64.base64encoder" is null

My code is

 XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                .setUsernameAndPassword(username, password)
                .setXmppDomain("") //This is fine as i removed this intentioanlly
                .setHost("localhost")
                .setPort(5222)
                .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                //.setHostnameVerifier((hostname, session) -> true) // Bypass hostname verification
                .build();

connection = new XMPPTCPConnection(config);
connection.connect();
connection.login(); //Here is the problem
connectionMap.put(username, connection);

Hi Naveen!

I suspect that you are missing a dependency in your classpath. Assuming that you are developing a desktop (as opposed to an Android) client, try replacing your dependencies with something like this:

<dependency>
    <groupId>org.igniterealtime.smack</groupId>
    <artifactId>smack-java8-full</artifactId>
    <version>4.4.8</version>
</dependency>

When you are developing on Android, make sure that your code uses org.jivesoftware.smack.android.AndroidSmackInitializer. This class initialized Smack for you on Android. Unfortunately it can’t do it automatically, you should call #initialize(Context) once before performing your first XMPP connection with Smack. Note that on Android 21 or higher you need to hold the ACCESS_NETWORK_STATE permission.

Sorry I forgot to mention, its not an android client. I am using spring boot 3.1.4 . my pom.xml is like this

	<dependency>
		<groupId>org.igniterealtime.smack</groupId>
		<artifactId>smack-core</artifactId>
		<version>4.4.8</version>
	</dependency>
	
	<dependency>
		<groupId>org.igniterealtime.smack</groupId>
		<artifactId>smack-tcp</artifactId>
		<version>4.4.8</version>
	</dependency>

	<dependency>
		<groupId>org.igniterealtime.smack</groupId>
		<artifactId>smack-im</artifactId>
		<version>4.4.8</version>
	</dependency>

	<dependency>
		<groupId>org.igniterealtime.smack</groupId>
		<artifactId>smack-extensions</artifactId>
		<version>4.4.8</version>
	</dependency>
	<dependency>
		<groupId>org.igniterealtime.smack</groupId>
		<artifactId>smack-xmlparser-xpp3</artifactId>
		<version>4.4.8</version>  Use the appropriate version 
	</dependency>
	<dependency>
		<groupId>org.igniterealtime.smack</groupId>
		<artifactId>smack-resolver-javax</artifactId>
		<version>4.4.8</version>  Use the appropriate version 
	</dependency>

I am working as a backend module for my fronend application written in js. I want to achieve live chatting using openfire. So i added smack as a client because Openfire doesnt provide websocket directly. I am new here and not able to resolve this issue.

Try replacing all those Smack dependencies with the one in my last message. I suspect that this will resolve your issue.

As an aside: If you are creating a front-end, you could consider creating the XMPP client directly in the front-end, instead of in the back-end. Instead of using Smack, you’d probably be using one of the javascript libraries that are available, like StanzaJS or Strophe or one of the others that are available.

Thanks, Its working now. I am very grateful .
and I will try 2nd approach too.
If you can help in a scenario, as you can see i have to add username and password for every user. But I dont want that. Is there any other way of doing that like using secret key ?

To protect the privacy of each user’s communication and data, each user is protected by its own credentials. I’m not seeing how using the same password for every user would be any more secure than using no passwords at all.

Thanks