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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:56:28+00:00 2026-05-28T16:56:28+00:00

I make Android application which must receive data from the page http://example.com/get.php?id=1 . For

  • 0

I make Android application which must receive data from the page http://example.com/get.php?id=1. For this I use the following method:

private String getData()
    {
        HttpClient httpClient = new DefaultHttpClient();
        HttpContext localContext = new BasicHttpContext(); // !!! application stops here
        HttpGet httpGet = new HttpGet("http://example.com/get.php?id=1");
        HttpResponse response = null;
            try {
                response = httpClient.execute(httpGet, localContext);
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        String result = "";

        BufferedReader reader = null;
            try {
                reader = new BufferedReader(
                    new InputStreamReader(
                      response.getEntity().getContent()
                    )
                  );
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        String line = null;
        try {
                while ((line = reader.readLine()) != null){
                  result += line + "\n";
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        // Now you have the whole HTML loaded on the result variable
        return result;
    }

I also added a permission to AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.repetitor_ent_free"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.INTERNET" />

The problem is that when I run the application on the device I get the error:
An unexpected stop the application MyApp (process com.android.myapp). Please try again.

  • 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-05-28T16:56:29+00:00Added an answer on May 28, 2026 at 4:56 pm

    You got android.os.NetworkOnMainThreadException, if you would like the better solution try to use AsyncTask. For more about threads look at ‘processes and threads‘ (please, read this guide carefully to avoid this issue in future).

    For example you could try one of these solutions:

    1) Use the Roman’s answer and add something like this:

    final StringBuilder sb = ... ;
    final TextView tv = ... ;
    
    tv.post(new Runnable() {
            public void run() {
                tv.setText(sb.toString());
            }
        });
    

    or use activity method:

    runOnUiThread(new Runnable() {
        public void run() {
            final StringBuilder sb = ... ;
            final TextView tv = ... ;
    
            tv.setText(sb.toString());
        }
    });
    

    2) Use AsyncTask:

    new AsyncTask<Void, Void, Void> () {
        protected Void doInBackground(Void... none) {
            //
            // your code
            //
    
            return null;
        }
        protected void onProgressUpdate(Void... none) {}
        protected void onPostExecute(Void none) {
            // use this to set the text
    
            final StringBuilder sb = ... ;
            final TextView tv = ... ;
    
            tv.setText(sb.toString());              
        }
    }.execute();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am due to make an android application which sends and recieves data from
I have an Android application from which I want to upload some data to
I Downloaded Svn Code IPcamera which an Android application for Live Streaming Media From
I am developing an Android application which would make intense use of Bluetooth RFCOMM
I'm working on an Android application which can make internet phone calls. I got
I am trying to make my Android application run some code when run from
I am trying to make an application which can connect from a mobile to
I have an Android application which talks to a public Data-API by calling URLs.
Project Description: I have to make an application in android which gets the Latitude
We have developed one android application which will send the request and receive the

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.