Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8476847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:17:32+00:00 2026-06-10T18:17:32+00:00

I try to write an android demo with asmack. There is an error named

  • 0

I try to write an android demo with asmack. There is an error named “host-unknown”. How can I solve that?

Here is what I see in LogCat:

03-16 08:31:10.671: I/getConnection(795): connect success
03-16 08:31:10.905: W/System.err(795): stream:error (host-unknown)
03-16 08:31:10.905: W/System.err(795):    at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:261)
03-16 08:31:10.912: W/System.err(795):    at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
03-16 08:31:10.912: W/System.err(795):    at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:71)

My code:

private static String host = "172.16.131.99";
private static int port = 5222;

private Button btnLogin;

private static XMPPConnection connection = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    btnLogin = (Button) findViewById(R.id.btnLogin);
    btnLogin.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (login()) {
                showMessage("Login success");
            } else {
                showMessage("Login failure");
            }
        }

    });
}

private XMPPConnection getConnection() {
    if (connection == null) {
        ConnectionConfiguration config = new ConnectionConfiguration(host, port, "");
        // use TLS
        config.setSecurityMode(SecurityMode.required);
        try {
            connection.connect();
            Log.i("getConnection", "connect success");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return connection;
}

private boolean login() {
    try {
        // login
        getConnection().login("admin", "123456");
        Log.i("Login", "login success");

        // set status
        Presence presence = new Presence(Presence.Type.available);
        getConnection().sendPacket(presence);
        Log.i("Login", "set status success");

        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}

private void showMessage(String message) {
    Toast.makeText(this, message, 1000).show();
}

Edit2

The XML file code is very simple, only just contain a button.

My xml file code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button android:id="@+id/btnLogin"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/login" />
</LinearLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:17:33+00:00Added an answer on June 10, 2026 at 6:17 pm
    1. First of all, I don’t think your code can run, because after you check connection == null, you do not init connection, just use:
      connection = new XMPPConnection(config);
    2. I have met the situation of un-known host, the problem is that we do not specify the service name in the constructor of the ConnectionConfiguration (you specified it as an empty string). Normally, if user’s email is of the form : user@something.com, the service name will be “something.com”. Anyway, you can get the exact service name after you are connected to the server (after connection.connect() succeeds) by using xmpp.getServiceName() (You can log to see the result, for example: Log.e(“Service Name”, xmpp.getServiceName()), then see the Logcat and copy the service name into the constructor).
    3. Enjoyed. 🙂
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm try to write first native android application and get follow Error There are
Hey there, i have one question.. i try to write an android app with
try to write a composite component that allows mutltiple text inputs. I read that
I try to write Activator action for changing current song rating. I now that
I try to write a macro in clojure that sets up a namespace and
Im using the eclipse plugin to try and write an android app. I looked
I am try to show epub book in android pad. I can parse the
I tried a simple file write program in Android. try { //File f1=new File(/sdcard/Prag.txt);
I would like to write an android app that basically layers an overlay on
There does not seem to be any Android manifest permission that needs to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.