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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:30:27+00:00 2026-06-13T11:30:27+00:00

I have the following json parser. public class JSONParserThreaded extends AsyncTask<String, Integer, String> {

  • 0

I have the following json parser.

    public class JSONParserThreaded extends AsyncTask<String, Integer, String>
{
    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";

    JSONObject processedjObj =null;

    JSONParserThreaded()
    {

    }

    @Override
    protected String doInBackground(String... params) 
    {
        // TODO Auto-generated method stub
        String url = params[0];
        try
        {
            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 parse the string to a JSON object
        try 
        {
            jObj = new JSONObject(json);
            setJSONObject(jObj);

        } 
        catch (JSONException e) 
        {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON String

        return "Sucess";
    }

    void setJSONObject(JSONObject jObject)
    {
        processedjObj = jObject;
    }

    JSONObject returnJSONObject()
    {
        return processedjObj;
    }

    @Override
    protected void onPostExecute(String result) 
    {
        super.onPostExecute(result);

    }
}

I’m using the parser in the following code

    public class CategoryScreenActivity extends Activity
{
    private static String url = "http://www.network.com/store/getCategories.php";

    static final String TAG_CATEGORY = "categories";
    static final String TAG_CATEGORY_NAME = "name";
    static final String TAG_CATEGORY_ID = "id";
    static final String TAG_CATEGORY_THUMBNAIL_URL = "thumbnail";
    static final String TAG_CATEGORY_IMAGE_MEDIUM_URL = "image_medium";
    static final String TAG_CATEGORY_IMAGE_LARGE_URL = "image_large";

    JSONArray categories = null;
    JSONObject wholeCategory = null;

    ListView mainListView;
    ListAdpater adapter;
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_view);

        ArrayList<HashMap<String, String>> categoryList = new ArrayList<HashMap<String, String>>();

        /*JSONParser jParser = new JSONParser();

        JSONObject json = jParser.getJSONFromURL(url);*/

        JSONParserThreaded jParserThread = new JSONParserThreaded();
        jParserThread.execute(url);

        try
        {
            //Getting Array of Categories
            wholeCategory = jParserThread.returnJSONObject();
            =>  categories = wholeCategory.getJSONArray(TAG_CATEGORY);  <=



            for(int i=0; i < categories.length(); i++)
            {
                JSONObject c = categories.getJSONObject(i);

                String cname = c.getString(TAG_CATEGORY_NAME);
                String cid = c.getString(TAG_CATEGORY_ID);
                String cThumbNailWithBackSlash = c.getString(TAG_CATEGORY_THUMBNAIL_URL);
                String cImageMediumWithBackSlash = c.getString(TAG_CATEGORY_IMAGE_MEDIUM_URL);
                String cImageLargeWithBackSLash = c.getString(TAG_CATEGORY_IMAGE_LARGE_URL);

                HashMap<String, String> categoryMap = new HashMap<String, String>();

                categoryMap.put(TAG_CATEGORY_ID,cid);
                categoryMap.put(TAG_CATEGORY_NAME, cname);
                categoryMap.put(TAG_CATEGORY_THUMBNAIL_URL, cThumbNailWithBackSlash);
                categoryMap.put(TAG_CATEGORY_IMAGE_MEDIUM_URL,cImageMediumWithBackSlash);
                categoryMap.put(TAG_CATEGORY_IMAGE_LARGE_URL,cImageLargeWithBackSLash);

                categoryList.add(categoryMap);
            }
        }
        catch(JSONException e)
        {
            e.printStackTrace();
        }
        mainListView = (ListView)findViewById(R.id.list);
        adapter = new ListAdpater(this, categoryList);
        mainListView.setAdapter(adapter);
    }


}

null pointer exception is being thrown from the line which is enclosed by “=> <=”
The app works fine in debugging mode, but not when I run it. Can anyone please help me out?

I have added the stack trace below.

enter image description here

  • 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-13T11:30:28+00:00Added an answer on June 13, 2026 at 11:30 am

    You have to delegate your networking to AsyncTask or IntentService. Doing networking on UI thread is wrong.

    Please read this article on that subject. And here is AsyncTask tutorial

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

Sidebar

Related Questions

I have the following JSON object as a String: [{Add1:101,Description:null,ID:1,Name:Bundesverfassung,Short:BV},{Add1:220,Description:null,ID:2,Name:Obligationenrecht,Short:OR},{Add1:210,Description:null,ID:3,Name:Schweizerisches Zivilgesetzbuch,Short:ZGB},{Add1:311_0,Description:null,ID:4,Name:Schweizerisches Strafgesetzbuch,Short:null}] Now i
I have the following POJO class for a JSON object: public class JSONChangeSet {
I have used following code to convert string to json and parse it. String
I have the following JSON String { name:Product, properties: { id: { type:number, description:Product
I have the following JSON string (from wikipedia http://en.wikipedia.org/wiki/JSON ) { name:Product, properties: {
I have the following JSON structure: [{ id:10, class: child-of-9 }, { id: 11,
I have the following json output when i call a sample webservice <string>[{Name:Ajay Singh,Company:Birlasoft
I have a JSON string that resembles the following: { foo : bar, id
I have a Restlet Service that looks like this: @POST @Produces(application/json) public String processImmediately(String
I have the following data: [{class:test,description:o hai,example:a,banana:b}] As this JSON data is already in

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.