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 9029047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:09:19+00:00 2026-06-16T07:09:19+00:00

I am trying to connection to my website from my application, for which I

  • 0

I am trying to connection to my website from my application, for which I am using URLConnection. I have caught UnknownHostException, but even then the application is crashing and log cat show the following error.

12-22 17:17:21.992: W/System.err(2222): java.net.UnknownHostException: Unable to resolve host "mywebsite.com": No address associated with hostname
12-22 17:17:22.012: W/System.err(2222):     at java.net.InetAddress.lookupHostByName(InetAddress.java:424)
12-22 17:17:22.012: W/System.err(2222):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
12-22 17:17:22.026: W/System.err(2222):     at java.net.InetAddress.getAllByName(InetAddress.java:214)
12-22 17:17:22.026: W/System.err(2222):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
12-22 17:17:22.026: W/System.err(2222):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
12-22 17:17:22.026: W/System.err(2222):     at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
12-22 17:17:22.026: W/System.err(2222):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
12-22 17:17:22.032: W/System.err(2222):     at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
12-22 17:17:22.032: W/System.err(2222):     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
12-22 17:17:22.032: W/System.err(2222):     at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
12-22 17:17:22.042: W/System.err(2222):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
12-22 17:17:22.042: W/System.err(2222):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
12-22 17:17:22.042: W/System.err(2222):     at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:282)
12-22 17:17:22.042: W/System.err(2222):     at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
12-22 17:17:22.052: W/System.err(2222):     at com.example.myapp$loadMessageAsync.doInBackground(FreeSms.java:85)
12-22 17:17:22.052: W/System.err(2222):     at com.example.myapp$loadMessageAsync.doInBackground(FreeSms.java:1)
12-22 17:17:22.062: W/System.err(2222):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-22 17:17:22.062: W/System.err(2222):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-22 17:17:22.072: W/System.err(2222):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-22 17:17:22.102: W/System.err(2222):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-22 17:17:22.102: W/System.err(2222):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-22 17:17:22.102: W/System.err(2222):     at java.lang.Thread.run(Thread.java:856)
12-22 17:17:22.122: W/System.err(2222): Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
12-22 17:17:22.122: W/System.err(2222):     at libcore.io.Posix.getaddrinfo(Native Method)
12-22 17:17:22.132: W/System.err(2222):     at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:59)
12-22 17:17:22.132: W/System.err(2222):     at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
12-22 17:17:22.132: W/System.err(2222):     ... 21 more
12-22 17:17:22.142: W/System.err(2222): Caused by: libcore.io.ErrnoException: getaddrinfo failed: ETIMEDOUT (Connection timed out)
12-22 17:17:22.162: W/System.err(2222):     ... 24 more
12-22 17:17:22.162: D/AndroidRuntime(2222): Shutting down VM
12-22 17:17:22.162: W/dalvikvm(2222): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
12-22 17:17:22.192: E/AndroidRuntime(2222): FATAL EXCEPTION: main
12-22 17:17:22.192: E/AndroidRuntime(2222): java.lang.NullPointerException
12-22 17:17:22.192: E/AndroidRuntime(2222):     at com.example.myapp$loadMessageAsync.onPostExecute(FreeSms.java:101)
12-22 17:17:22.192: E/AndroidRuntime(2222):     at com.example.myapp$loadMessageAsync.onPostExecute(FreeSms.java:1)
12-22 17:17:22.192: E/AndroidRuntime(2222):     at android.os.AsyncTask.finish(AsyncTask.java:631)
12-22 17:17:22.192: E/AndroidRuntime(2222):     at android.os.AsyncTask.access$600(AsyncTask.java:177)
12-22 17:17:22.192: E/AndroidRuntime(2222):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
12-22 17:17:22.192: E/AndroidRuntime(2222):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-22 17:17:22.192: E/AndroidRuntime(2222):     at android.os.Looper.loop(Looper.java:137)
12-22 17:17:22.192: E/AndroidRuntime(2222):     at android.app.ActivityThread.main(ActivityThread.java:5039)
12-22 17:17:22.192: E/AndroidRuntime(2222):     at java.lang.reflect.Method.invokeNative(Native Method)
12-22 17:17:22.192: E/AndroidRuntime(2222):     at java.lang.reflect.Method.invoke(Method.java:511)
12-22 17:17:22.192: E/AndroidRuntime(2222):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-22 17:17:22.192: E/AndroidRuntime(2222):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-22 17:17:22.192: E/AndroidRuntime(2222):     at dalvik.system.NativeStart.main(Native Method)

CODE

public class MainActivity extends Activity {

private Button btnSkipContinue;
private TextView txtMessage,txtVersion;
private StringBuilder response; 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);
    btnSkipContinue = (Button) findViewById(R.id.btnSkipCon);
    btnSkipContinue.setVisibility(View.GONE);
    txtMessage = (TextView) findViewById(R.id.txtMsgForUsers);      
    btnSkipContinue.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {
            finish();
            Intent intent = new Intent(MainActivity.this, MyPage.class);
            startActivity(intent);
        }
    });

    if (isOnline()) {
        try {
            new loadMessageAsync().execute();
        } catch (Exception ex) {
            txtMessage.setText("Error while loading message. Cannot connect to server....");
            btnSkipContinue.setVisibility(View.VISIBLE);
            btnSkipContinue.setText("Continue");
        }
    } else {
        Toast.makeText(getApplicationContext(), "No Internet Access", Toast.LENGTH_SHORT).show();
    }
}

public boolean isOnline() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        return true;
    }
    return false;
}

private class loadMessageAsync extends AsyncTask<Void, Void, Void> {

    @Override
    protected Void doInBackground(Void... arg0) {
        try {
            URLConnection connection = new URL("http://mywebsite.com/new/Messages.aspx").openConnection();
            connection.setConnectTimeout(60000);
            connection.setRequestProperty("Accept-Charset", "UTF-8");
            InputStream responseStream = connection.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(responseStream));
            response = new StringBuilder();
            String line;
            while ((line = br.readLine()) != null) {
                response.append(line);
            }
        } catch (UnknownHostException ex) {
            response.append("<html><body>Error while loading message. Cannot connect to server.</body></html>");
        } catch (IOException ex) {
            response.append("<html><body>Error while loading message. Cannot connect to server..</body></html>");
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        try {
            txtMessage.setText(Html.fromHtml(response.toString()));
        } catch (Exception ex) {
            txtMessage.setText("Error while loading message. Cannot connect to server...");
        }
        btnSkipContinue.setVisibility(View.VISIBLE);
        btnSkipContinue.setText("Continue");
    }

}
}
  • 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-16T07:09:21+00:00Added an answer on June 16, 2026 at 7:09 am

    UnknownHostException is being handled, but it’s an unhandled NullPointerException that is crashing you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application, I'm trying to download a file from my website, but I'm
I am trying to do ssh connection using cygwin. I have followed instructions given
I'm trying to establish a HTTP persistent connection from a Silverlight application to a
I'm trying to send email with my website's address from a C# application. This
I am trying to write a C++ program to read from a website using
I am trying to close a memcached connection to start a new one. But
I am trying to store a db connection from a crontoller and trying to
I'm trying to start a connection from my Arduino Mega ADK to my Android
Okay, we've got an application which consists of a website hosting several ASMX webservices,
In a shoes application am trying to download stuff from some internal websites. I

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.