Small test of Asmack XMPP client library

Evelina Vrabie

Dedicated coder, occasional blogger, hackathon goer and friendly team mate.

You may also read...

  • Ajay

    Hi, Thanks for post this tutorial,
    I’m getting error as
    Could not find class ‘’, referenced from method org.jivesoftware.smack.util.DNSUtil.

    01-13 07:50:10.357: E/AndroidRuntime(18002): java.lang.ExceptionInInitializerError
    01-13 07:50:10.357: E/AndroidRuntime(18002): at org.jivesoftware.smack.ConnectionConfiguration.(
    01-13 07:50:10.357: E/AndroidRuntime(18002): at org.jivesoftware.smack.XMPPConnection.(
    01-13 07:50:10.357: E/AndroidRuntime(18002): at
    01-13 07:50:10.357: E/AndroidRuntime(18002): at
    01-13 07:50:10.357: E/AndroidRuntime(18002): at$1600(
    01-13 07:50:10.357: E/AndroidRuntime(18002): at$H.handleMessage(

    i included smack libraries also, tell me how to resolve this problem.

  • Ujjwal

    can anyone tell me as to how can i fetch chat history using asmack..???

  • FriendlyPerson

    I copied your example but choose a later android version and get a NetworkInMainThreadException. How to fix this?

    05-05 13:04:49.379: E/AndroidRuntime(8530): java.lang.RuntimeException: Unable to create service de.homebrew.service.XMPPService: android.os.NetworkOnMainThreadException

    And it seems to be comming from this:

    05-05 13:04:49.379: E/AndroidRuntime(8530): at de.homebrew.service.XMPPService.onCreate(

    • Larry

      I had the same problem. The problem is that you are making a network connection on the main thread. You can solve this by making async background connection or the lazy way:

      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

      This will make it work, you mas put it in the onCreate of the (main) activity. Don’t use this way for a production app is bad programming

  • Test

    Hi, very nice example and i´m able to connect to gtalk.
    I´ve added a toasts to see a message if i´m connected and my device shows up in gmail chat as available. So i added another toast right under Log.i(TAG, “Xmpp message received: ‘” + message.getBody() + “‘ on thread: ” + getThreadSignature()); but the toast never shows.

    any ideas?


    • daniele_athome

      That’s because you are not in the main (UI) thread. You must start a Toast within the UI thread. To do so, send a runnable to a Handler connected to an existing activity or service. Activities have a useful method “runInUIThread” that does this implicitly.

  • Steve

    Thanks for posting this, I’m just getting start with Android and Asmack and this was very helpful.

    • Reza

      i have a openfire server ,but i dont know, how setup & use asmack
      Please Help me