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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:23:03+00:00 2026-06-16T13:23:03+00:00

There’s obviously something I’m missing here – I’ve been through the developer.android reference and

  • 0

There’s obviously something I’m missing here – I’ve been through the developer.android reference and guide material on AsyncTasks and threads – plus scores of posts here, and it’s not my first rodeo either.
I have an inner AsyncTask Class that grabs JSON from a url and parses it. I keep running into access issues and can’t seem to get the right combination. Here’s a chunk of code partway through the main public class, which is “Consumer”. I can ad more code, but I believe this will demonstrate what’s needed. TIA!

// some method
if(arg1==b){
    b.setClickable(false);  
    a.setClickable(true); 
    // next, build the url
    srchStr = urla + "&q=upc:" + value1 + urlc;
    // execute the parser
    new JSONParser().execute(value1);
}

// ...

static class JSONParser extends AsyncTask<String, Void, JSONObject> {
    static InputStream is = null; 
    static JSONObject jObj = null; 
    static String json = "";      


    public JSONObject doInBackground(String url) {    //getJSONFromUrl
        // Making HTTP request 
        try { 
            // defaultHttpClient 
            DefaultHttpClient httpClient = new DefaultHttpClient(); 
            HttpPost httpPost = new HttpPost(url);    
            HttpResponse httpResponse = httpClient.execute(httpPost); 
            HttpEntity httpEntity = httpResponse.getEntity(); 
            is = httpEntity.getContent();            

        } catch (UnsupportedEncodingException e) { 
            e.printStackTrace(); 
        } catch (ClientProtocolException e) { 
            e.printStackTrace(); 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 

        try { 
            BufferedReader reader = new BufferedReader(new InputStreamReader( 
                    is, "iso-8859-1"), 8); 
            StringBuilder sb = new StringBuilder(); 
            String line = null; 
            while ((line = reader.readLine()) != null) { 
                sb.append(line + "\n"); 
            } 
            is.close(); 
            json = sb.toString(); 
        } catch (Exception e) { 
            Log.e("Buffer Error", "Error converting result " + e.toString()); 
        } 

        // try to parse the string to a JSON object 
        try { 
            jObj = new JSONObject(json); 
        } catch (JSONException e) { 
            Log.e("JSON Parser", "Error parsing data " + e.toString()); 
        } 

        // return JSON String 
        return jObj;      
    } 
    protected void onPostExecute(String result) {
        //TextView tv2 = (TextView) findViewById(R.id.tv2);
        tv2.setText("json"); // txt.setText(result);


    }       
}

The error comes up on the line:

static class JSONParser extends AsyncTask<String, Void, JSONObject> {

which is:

The type Consumer.JSONParser must implement the inherited abstract
method AsyncTask.doInBackground(String…)

….yet, the doInBackground method is there…..

I hope this is sufficient info to troubleshoot this. I expect it is something simple that I have been missing….

Update:
I made the recommended changes, as they certainly made sense, however it now compiles, but won’t run. Please take another look and let me know if I am mistaken, or if this is another issue…
Here’s the updated code:

if(arg1==b){
    b.setClickable(false);  
    a.setClickable(true); 
    // next, build the url
    srchStr = urla + "&q=upc:" + value1 + urlc;
    // execute the parser
    new JSONParser().execute(value1);
    }   
}

    static class JSONParser extends AsyncTask<String, Void, JSONObject> {
    static InputStream is = null; 
    static JSONObject jObj = null; 
    static String json = "";      


     public JSONObject doInBackground(String... urls) {       //getJSONFromUrl
         Consumer.srchStr = urls[0];
        // Making HTTP request 
        try { 
            // defaultHttpClient 
            DefaultHttpClient httpClient = new DefaultHttpClient(); 
            HttpPost httpPost = new HttpPost(srchStr);    
            HttpResponse httpResponse = httpClient.execute(httpPost); 
            HttpEntity httpEntity = httpResponse.getEntity(); 
            is = httpEntity.getContent();            

        } catch (UnsupportedEncodingException e) { 
            e.printStackTrace(); 
        } catch (ClientProtocolException e) { 
            e.printStackTrace(); 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 

        try { 
            BufferedReader reader = new BufferedReader(new InputStreamReader( 
                    is, "iso-8859-1"), 8); 
            StringBuilder sb = new StringBuilder(); 
            String line = null; 
            while ((line = reader.readLine()) != null) { 
                sb.append(line + "\n"); 
            } 
            is.close(); 
            json = sb.toString(); 
        } catch (Exception e) { 
            Log.e("Buffer Error", "Error converting result " + e.toString()); 
        } 

        // try to parse the string to a JSON object 
        try { 
            jObj = new JSONObject(json); 
        } catch (JSONException e) { 
            Log.e("JSON Parser", "Error parsing data " + e.toString()); 
        } 

        // return JSON String 
        return jObj;      
    } 
    protected void onPostExecute(JSONObject result) {
        //TextView tv2 = (TextView) findViewById(R.id.tv2);
        result = jObj;
        tv2.setText("result"); // txt.setText(result);          
    }       
}
}

and the logcat text:

12-29 21:35:25.530: W/dalvikvm(2237): threadid=7: thread exiting with uncaught exception (group=0x4001d800)
12-29 21:35:25.605: E/AndroidRuntime(2237): FATAL EXCEPTION: AsyncTask #1
12-29 21:35:25.605: E/AndroidRuntime(2237): java.lang.RuntimeException: An error occured while executing doInBackground()
12-29 21:35:25.605: E/AndroidRuntime(2237):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
12-29 21:35:25.605: E/AndroidRuntime(2237):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
12-29 21:35:25.605: E/AndroidRuntime(2237):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
12-29 21:35:25.605: E/AndroidRuntime(2237):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
12-29 21:35:25.605: E/AndroidRuntime(2237):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-29 21:35:25.605: E/AndroidRuntime(2237):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
12-29 21:35:25.605: E/AndroidRuntime(2237):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
12-29 21:35:25.605: E/AndroidRuntime(2237):     at java.lang.Thread.run(Thread.java:1096)
12-29 21:35:25.605: E/AndroidRuntime(2237): Caused by: java.lang.IllegalStateException: Target host must not be null, or set in parameters.
12-29 21:35:25.605: E/AndroidRuntime(2237):     at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:561)
12-29 21:35:25.605: E/AndroidRuntime(2237):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:292)
12-29 21:35:25.605: E/AndroidRuntime(2237):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
12-29 21:35:25.605: E/AndroidRuntime(2237):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
12-29 21:35:25.605: E/AndroidRuntime(2237):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
12-29 21:35:25.605: E/AndroidRuntime(2237):     at com.clicsys.pbuster.Consumer$JSONParser.doInBackground(Consumer.java:116)
12-29 21:35:25.605: E/AndroidRuntime(2237):     at com.clicsys.pbuster.Consumer$JSONParser.doInBackground(Consumer.java:1)
12-29 21:35:25.605: E/AndroidRuntime(2237):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
12-29 21:35:25.605: E/AndroidRuntime(2237):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-29 21:35:25.605: E/AndroidRuntime(2237):     ... 4 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-16T13:23:04+00:00Added an answer on June 16, 2026 at 1:23 pm

    You need to change your method signature so it is

    public JSONObject doInBackground(String... url)
    

    This is because doInBackground() accepts in an infinite amount of arguments. To acess the String you want, you can then do

    String currentUrl = url [0];
    

    Also, your onPostExecute needs a JSONObject as the argument. This will not use the ... because onPostExecute() only accepts in 1 argument.

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

Sidebar

Related Questions

There is something I miss with the notion of Synchronizing code in Android. Scenario
There's a webpage with something annoying on it which I'd like to hide every
There is something strange happening. Param interceptor is the one in charge to take
There's a nice explanation here of how to use ggplot2 to create a scatterplot,
There is a moment in my app, that I need to force to show
There is a column that exists in 2 tables. In table 1, this column
There's a Rails 3.2.3 web application which doesn't use any database. But in spite
There is a directed graph having a single designated node called root from which
There are two intents on the receiver side which are called from the same
There are nice SO question and answers about this issue, but these options didn't

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.