适用于OpenFire Server的Android客户端

时间:2014-10-15 13:12:50

标签: android xmpp openfire smack asmack

我正在开发一个Android聊天应用程序,它必须连接到我的机器上运行的OpenFire服务器。我尝试了很多选项,但连接都无法连接。如果你们中的任何人尽早了解相同情况,请提供帮助。我在我的应用程序中使用smack.jar。以下是我的代码中的几行:

    String username = "test@inbasdpc06783";
    String password = "admin";



    // Create a connection
//        ConnectionConfiguration connConfig =
//                new ConnectionConfiguration(host, Integer.parseInt(port), service);




   ConnectionConfiguration connConfig = new ConnectionConfiguration("inbasdpc06783");


   connConfig.setCompressionEnabled(true);
   connConfig.setSASLAuthenticationEnabled(true);



    XMPPConnection connection = new XMPPConnection(connConfig);

    try {
        Log.d("XMPPClient", "[SettingsDialog] BEFORE Connected to " + connection.getHost());
        connection.connect();            
        Log.d("XMPPClient", "[SettingsDialog] AFTER Connected to connection.isConnected()>>>" + connection.isConnected());            
    } catch (XMPPException ex) {
        Log.e("XMPPClient", "[SettingsDialog] Failed to connect to " + connection.getHost());
        Log.e("XMPPClient", ex.toString());
        xmppClient.setConnection(null);
    }

我收到以下错误:

10-15 18:39:02.759: E/dalvikvm(17668): Could not find class 'javax.naming.directory.InitialDirContext', referenced from method org.jivesoftware.smack.util.DNSUtil.<clinit>
10-15 18:39:02.800: E/AndroidRuntime(17668): FATAL EXCEPTION: main
10-15 18:39:02.800: E/AndroidRuntime(17668): java.lang.ExceptionInInitializerError
10-15 18:39:02.800: E/AndroidRuntime(17668):    at org.jivesoftware.smack.ConnectionConfiguration.<init>(ConnectionConfiguration.java:81)
10-15 18:39:02.800: E/AndroidRuntime(17668):    at org.apache.android.xmpp.SettingsDialog.onClick(SettingsDialog.java:51)
10-15 18:39:02.800: E/AndroidRuntime(17668):    at android.view.View.performClick(View.java:3538)
10-15 18:39:02.800: E/AndroidRuntime(17668):    at android.view.View$PerformClick.run(View.java:14330)
10-15 18:39:02.800: E/AndroidRuntime(17668):    at android.os.Handler.handleCallback(Handler.java:608)
10-15 18:39:02.800: E/AndroidRuntime(17668):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-15 18:39:02.800: E/AndroidRuntime(17668):    at android.os.Looper.loop(Looper.java:156)
10-15 18:39:02.800: E/AndroidRuntime(17668):    at android.app.ActivityThread.main(ActivityThread.java:4987)
10-15 18:39:02.800: E/AndroidRuntime(17668):    at java.lang.reflect.Method.invokeNative(Native Method)
10-15 18:39:02.800: E/AndroidRuntime(17668):    at java.lang.reflect.Method.invoke(Method.java:511)
10-15 18:39:02.800: E/AndroidRuntime(17668):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-15 18:39:02.800: E/AndroidRuntime(17668):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-15 18:39:02.800: E/AndroidRuntime(17668):    at dalvik.system.NativeStart.main(Native Method)
10-15 18:39:02.800: E/AndroidRuntime(17668): Caused by: java.lang.NoClassDefFoundError: javax.naming.directory.InitialDirContext
10-15 18:39:02.800: E/AndroidRuntime(17668):    at org.jivesoftware.smack.util.DNSUtil.<clinit>(DNSUtil.java:47)
10-15 18:39:02.800: E/AndroidRuntime(17668):    ... 13 more

1 个答案:

答案 0 :(得分:0)

您似乎正在使用Smack版本&lt; 4.1它不适用于Android。另请参阅Android and XMPP: Currently available solutions