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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:04:04+00:00 2026-06-12T00:04:04+00:00

In the code I try to read from a web service with an http

  • 0

In the code I try to read from a web service with an http client. Then I want to write the Responce Phrase of the http responce to a text view. The UI is accessed through onPostExecute() so I don’t know why I get this exception.

This is the code:

public class CustomersScreen extends Activity {

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

public void LoginClicked(View view) {
    new Get_data().execute("http://localhost:51982/WcfDataService1.svc/Genre");
}

private class Get_data extends AsyncTask <String, Void, String> {

    @Override
    protected String doInBackground(String... url) {
        //InputStream instream = null;
        HttpClient httpclient = new DefaultHttpClient();
        HttpGet request = new HttpGet(url[0]);
        HttpResponse response = null;
        try {
            response = httpclient.execute(request);
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        String phrase = response.getStatusLine().getReasonPhrase();

        return phrase;
    }

    @Override
    protected void onPostExecute(String phrase) {
        TextView t = (TextView) findViewById(R.id.textView3);
        t.setText(phrase);
    }

}

}

and the log cat :

09-28 09:43:34.239: E/AndroidRuntime(679): FATAL EXCEPTION: AsyncTask #1
09-28 09:43:34.239: E/AndroidRuntime(679): java.lang.RuntimeException: An error occured while executing doInBackground()
09-28 09:43:34.239: E/AndroidRuntime(679):  at android.os.AsyncTask$3.done(AsyncTask.java:278)
09-28 09:43:34.239: E/AndroidRuntime(679):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
09-28 09:43:34.239: E/AndroidRuntime(679):  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
09-28 09:43:34.239: E/AndroidRuntime(679):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
09-28 09:43:34.239: E/AndroidRuntime(679):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
09-28 09:43:34.239: E/AndroidRuntime(679):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
09-28 09:43:34.239: E/AndroidRuntime(679):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
09-28 09:43:34.239: E/AndroidRuntime(679):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
09-28 09:43:34.239: E/AndroidRuntime(679):  at java.lang.Thread.run(Thread.java:856)
09-28 09:43:34.239: E/AndroidRuntime(679): Caused by: java.lang.NullPointerException
09-28 09:43:34.239: E/AndroidRuntime(679):  at com.test.CustomersScreen$Get_data.doInBackground(CustomersScreen.java:46)
09-28 09:43:34.239: E/AndroidRuntime(679):  at com.test.CustomersScreen$Get_data.doInBackground(CustomersScreen.java:1)
09-28 09:43:34.239: E/AndroidRuntime(679):  at android.os.AsyncTask$2.call(AsyncTask.java:264)
09-28 09:43:34.239: E/AndroidRuntime(679):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
09-28 09:43:34.239: E/AndroidRuntime(679):  ... 5 more
  • 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-12T00:04:06+00:00Added an answer on June 12, 2026 at 12:04 am
    Caused by: java.lang.NullPointerException
    09-28 09:43:34.239: E/AndroidRuntime(679):  at com.test.CustomersScreen$Get_data.doInBackground(CustomersScreen.java:46)
    

    You have a NPE in line 46 of your class. The code, posted lacks some lines obviously, but I suppose it’s this line String phrase = response.getStatusLine().getReasonPhrase(); as response would be null if anything goes wrong with the httpclient.execute(request);

    So, just put that line within the try/catch block as well and add a simple return null; at the end of the method instead.

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

Sidebar

Related Questions

I want to send the JSON text {} to a web service and read
In the following code, I try to read data from a plist: -(void)readPreferences {
I am trying to send a byte[] from a client to a web service.
I'm running a java code for getting info from a google-app-engine web service (testeserjaum.appspot.com),
I am having a problem to read large data from xml web service the
I try to read file /proc/'pid'/status, using c program. The code is as follows,
What will be the code when I try to make a combo box read
I have used the code below to read rfid tag values. try { if
I am working on a code in C#.NET to create a web service that
I call a .Net web service from my Blackberry app. After having nothing but

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.