0

I'm still new in using Smack API. I got this exception while trying to log in.

Here's my code :

XMPPTCPConnectionConfiguration configuration = XMPPTCPConnectionConfiguration.builder()
                .setUsernameAndPassword(username, password)
                .setXmppDomain(domain)
                .setHostAddress(InetAddress.getByName(host))
                .setPort(port)
                .build();
XMPPTCPConnection connection = new XMPPTCPConnection(configuration);
connection.connect();
connection.login();

Here's my log :

Exception in thread "main" java.lang.NullPointerException
at java.util.Collections$UnmodifiableCollection.<init>(Collections.java:1026)
at java.util.Collections$UnmodifiableSet.<init>(Collections.java:1128)
at java.util.Collections.unmodifiableSet(Collections.java:1118)
at org.jivesoftware.smack.ConnectionConfiguration.getEnabledSaslMechanisms(ConnectionConfiguration.java:476)
at org.jivesoftware.smack.SASLAuthentication.selectMechanism(SASLAuthentication.java:359)
at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:191)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.loginInternal(XMPPTCPConnection.java:385)
at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:491)
at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:448)
at Main.main(Main.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Steve Lukis
  • 420
  • 4
  • 10

1 Answers1

1

Case closed. At first, I only used smack core and smack tcp as libraries. It turns out that you need to use smack sasl as a library in my case. Download smack here and copy smack sasl jar into libs folder as a library.

Steve Lukis
  • 420
  • 4
  • 10
  • I recommend using a build system (/IDE) that is able to resolve Maven dependencies. By just copying the Smack jar files, you will certainly miss some transitive dependencies, which will eventually cause further problems. – Flow Jun 28 '17 at 21:12
  • @Flow i am having the same issue . Can you please provide the gradle dependency for sasl . I have read [Here](https://github.com/igniterealtime/Smack/wiki/Smack-4.2-Readme-and-Upgrade-Guide) but there is no dependency regarding sasl . – ADM Feb 01 '18 at 09:52
  • smack-java7 and smack-android are the entry points which will pull in all transitive dependencies – Flow Feb 01 '18 at 09:57
  • Got it Thx for response . – ADM Feb 01 '18 at 10:06
  • I a pretty new to XMPP . Can you please look into [This question](https://stackoverflow.com/questions/48542534/how-to-manage-chat-threads-in-xmpp-openfire) and guide us in right direction. We are kind of stuck here . Any help will be appreciated . Thx – ADM Feb 01 '18 at 10:08
  • @Flow would you please look into [This question](https://stackoverflow.com/questions/48542534/how-to-manage-chat-threads-in-xmpp-openfire) of ours .We are stuck here from 3 days please drive us in right direction . – ADM Feb 02 '18 at 05:29