在Android上使用aSmack连接本地xmpp服务器并获取“IllegalStateException:No DNS resolver active”。

时间:2013-08-10 03:39:52

标签: android xmpp asmack

今天我实现了一个android客户端连接本地xmpp服务器,当我的代码执行下面的代码时,我的android应用程序会中止,请帮帮我:

public boolean login(String a, String p){
        ConnectionConfiguration config = new ConnectionConfiguration("192.168.1.119");
        config.setSASLAuthenticationEnabled(false);
        config.setDebuggerEnabled(false);
        XMPPConnection connection = new XMPPConnection(config);
        try{
            System.out.println("hehe");
            connection.connect();
            connection.login(a, p);
            //Presence presence = new Presence(Presence.Type.available);
            //presence.setStatus("hehe");
            //connection.sendPacket(presence);
            return true;
        }catch(XMPPException e){
            e.printStackTrace();
        }
        return false;
    }

我收到了以下错误:

08-09 23:30:19.091: E/AndroidRuntime(1860): FATAL EXCEPTION: main
08-09 23:30:19.091: E/AndroidRuntime(1860): java.lang.IllegalStateException: No DNS resolver active.
08-09 23:30:19.091: E/AndroidRuntime(1860):     at org.jivesoftware.smack.util.DNSUtil.resolveDomain(DNSUtil.java:121)
08-09 23:30:19.091: E/AndroidRuntime(1860):     at org.jivesoftware.smack.util.DNSUtil.resolveXMPPDomain(DNSUtil.java:85)
08-09 23:30:19.091: E/AndroidRuntime(1860):     at org.jivesoftware.smack.ConnectionConfiguration.<init>(ConnectionConfiguration.java:107)
08-09 23:30:19.091: E/AndroidRuntime(1860):     at com.example.chatrom.ClientConServer.login(ClientConServer.java:16)
08-09 23:30:19.091: E/AndroidRuntime(1860):     at com.example.chatrom.LogIn$1.onClick(LogIn.java:32)
08-09 23:30:19.091: E/AndroidRuntime(1860):     at android.view.View.performClick(View.java:4240)
08-09 23:30:19.091: E/AndroidRuntime(1860):     at android.view.View$PerformClick.run(View.java:17721)
08-09 23:30:19.091: E/AndroidRuntime(1860):     at android.os.Handler.handleCallback(Handler.java:730)
08-09 23:30:19.091: E/AndroidRuntime(1860):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-09 23:30:19.091: E/AndroidRuntime(1860):     at android.os.Looper.loop(Looper.java:137)
08-09 23:30:19.091: E/AndroidRuntime(1860):     at android.app.ActivityThread.main(ActivityThread.java:5103)
08-09 23:30:19.091: E/AndroidRuntime(1860):     at java.lang.reflect.Method.invokeNative(Native Method)
08-09 23:30:19.091: E/AndroidRuntime(1860):     at java.lang.reflect.Method.invoke(Method.java:525)
08-09 23:30:19.091: E/AndroidRuntime(1860):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-09 23:30:19.091: E/AndroidRuntime(1860):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-09 23:30:19.091: E/AndroidRuntime(1860):     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

按照aSmack文档中的自述文件并致电

SmackAndroid.init(Context)

请参阅流程回答here