我正在使用Android-Studio连接到Openfire(XMPP)和Asmack。示例代码是
ConnectionConfiguration connConfig = new ConnectionConfiguration(HOST, 5222);
XMPPConnection connection = new XMPPTCPConnection(connConfig);
try {
connection.connect();
Log.i("XMPPChatDemoActivity", "[SettingsDialog] Connected to "+connection.getHost());
} catch (XMPPException ex) {
Log.e("XMPPChatDemoActivity", "[SettingsDialog] Failed to connect to "+ connection.getHost()); Log.e("XMPPChatDemoActivity", ex.toString());
setConnection(null);
} catch (IOException ex) {
Log.e("XMPPChatDemoActivity", ex.toString());
} catch (SmackException ex) {
Log.e("XMPPChatDemoActivity", ex.toString());
}
我收到此错误
.xmpp E/XMPPChatDemoActivity﹕ [SettingsDialog] Failed to connect to null
E/XMPPChatDemoActivity﹕ org.jivesoftware.smack.SmackException$ConnectionException
E/XMPPChatDemoActivity﹕ org.jivesoftware.smack.SmackException$NotConnectedException
这显然意味着connection.getHost()为null。很多人都在说使用
AndroidConnectionConfiguration connConfig = new AndroidConnectionConfiguration(HOST,PORT, SERVICE);
发布了ConnectionCOnfiguration。但是没有名为AndroidConnectionConfiguration的类。
我正在使用Android Studio和Asmack asmack-android-8-4.0.6.jar