使用 Smack 4.1 的 XMPP 客户端在登录期间提供 NullPointerException
我正在尝试使用Smack 4.1.0-rc3来实现连接到ejabberd xmpp服务器的java xmpp客户端。我正在使用以下代码连接到服务器。
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();
在执行'connection.login()'时,我得到了以下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)
我是否在代码中做错了什么?你能给我指出一个使用Smack 4.1.0-rc3的正确例子吗?