XMPPConnection Error in android

2019-07-09 05:42发布

I am using the same code from this link Google chat

But I got the below error.

04-12 09:13:55.903: ERROR/AndroidRuntime(362): FATAL EXCEPTION: Thread-8
04-12 09:13:55.903: ERROR/AndroidRuntime(362): java.lang.ExceptionInInitializerError
04-12 09:13:55.903: ERROR/AndroidRuntime(362):     at org.jivesoftware.smack.ConnectionConfiguration.<init>(ConnectionConfiguration.java:99)
04-12 09:13:55.903: ERROR/AndroidRuntime(362):     at org.jivesoftware.smack.XMPPConnection.<init>(XMPPConnection.java:131)
04-12 09:13:55.903: ERROR/AndroidRuntime(362):     at com.ex.HelloFormStuffActivity.HelloFormStuffActivity$1.run(HelloFormStuffActivity.java:38)
04-12 09:13:55.903: ERROR/AndroidRuntime(362):     at java.lang.Thread.run(Thread.java:1096)
04-12 09:13:55.903: ERROR/AndroidRuntime(362): Caused by: java.lang.NoClassDefFoundError: javax.naming.directory.InitialDirContext
04-12 09:13:55.903: ERROR/AndroidRuntime(362):     at org.jivesoftware.smack.util.DNSUtil.<clinit>(DNSUtil.java:50)
04-12 09:13:55.903: ERROR/AndroidRuntime(362):     ... 4 more

I have no idea why this error is coming. Can any one help me?

标签: android xmpp
3条回答
倾城 Initia
2楼-- · 2019-07-09 05:59

I got this error after I updated the android plugin for eclipse as well as the android SDK tools/platform-tools (my project worked fine before I updated).

To fix I went to Properties -> Java Build Path -> Order and Export Tab. I checked the box next to the asmack jar I am using (the one from BEEM). Then I moved it to the top. Originally it wouldn't work unless it was at the top so make sure you try that.

查看更多
放我归山
3楼-- · 2019-07-09 06:03

ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com", 5222,"chat.facebook.com");

        XMPPConnection myConn = new XMPPConnection(config);
        config.setSASLAuthenticationEnabled(true);
       config.setDebuggerEnabled(true);

        try{
      myConn.connect();
//username is  no @chat.facebook.com
myConn.login("rajeshXXXXX","XXXXXXX" );




        }
        catch (Exception e) {
            System.out.println(e.toString());
        }

//Its working fine for me finally, use asmack-2010.05.07.jar git://gist.github.com/925250.git

查看更多
Evening l夕情丶
4楼-- · 2019-07-09 06:06

It seems like you are using Ignite's Smack API. The original Smack API is intended for desktop usage and uses the Java Naming and Directory Interface (JNDI) that is used for LDAP and other directory-related stuff. JNDI is not included in Android, i.e. the package javax.naming does not exist. There is an Android port called asmack which will work for you. You simply have to replace the Smack jar by asmack's jar.

You can find asmack here: https://github.com/flowdalic/asmack

查看更多
登录 后发表回答