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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:54:30+00:00 2026-06-14T20:54:30+00:00

I made a simple AsyncTask class to display data in ListView with the help

  • 0

I made a simple AsyncTask class to display data in ListView with the help of this stackoverflow question.
But the AsyncTask onPostExecute is not being called.

This is my code:

public class Start extends SherlockActivity {

// JSON Node names
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";


// category JSONArray
JSONArray category = null;

private ListView lv;


@Override
public void onCreate(Bundle savedInstanceState) {
    setTheme(SampleList.THEME); //Used for theme switching in samples
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test);


    new MyAsyncTask().execute("http://....");

    // Launching new screen on Selecting Single ListItem
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // getting values from selected ListItem
            String name = ((TextView) view.findViewById(R.id.name)).getText().toString();
            String cost = ((TextView) view.findViewById(R.id.mail)).getText().toString();

            // Starting new intent
            Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
            in.putExtra("categoryname", name);
            System.out.println(cost);
            in.putExtra("categoryid", cost);
            startActivity(in);


        }
    });
}

public class MyAsyncTask extends AsyncTask<String, Void, ArrayList<HashMap<String, String>> > {
    // Hashmap for ListView
    ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();

    @Override
    protected ArrayList<HashMap<String, String>> doInBackground(String... params) {
        // Creating JSON Parser instance
        JSONParser jParser = new JSONParser();
        // getting JSON string from URL
        category = jParser.getJSONArrayFromUrl(params[0]);
        try {

            // looping through All Contacts
            for(int i = 0; i < category.length(); i++){
                JSONObject c = category.getJSONObject(i);

                // Storing each json item in variable
                String id = c.getString(TAG_ID);
                String name = c.getString(TAG_NAME);


                // creating new HashMap
                HashMap<String, String> map = new HashMap<String, String>();

                // adding each child node to HashMap key => value
                map.put(TAG_ID, id);
                map.put(TAG_NAME, name);

                // adding HashList to ArrayList
                contactList.add(map);

            }
        } catch (JSONException e) {
            Log.e("log_tag", "Error parsing data "+e.toString());
        }
        return contactList;
        }

        @Override
        protected void onPostExecute(ArrayList<HashMap<String, String>> result) {
            ListAdapter adapter = new SimpleAdapter(Start.this, result , R.layout.list_item, 
                    new String[] { TAG_NAME, TAG_ID }, 
                    new int[] { R.id.name, R.id.mail });

            // selecting single ListView item
            lv = (ListView) findViewById(R.id.ListView);
            lv.setAdapter(adapter);

        }
}
}

Eclipse:

11-25 11:40:31.896: E/AndroidRuntime(917): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.essentials/de.main.Start}

                                         :java.lang.NullPointerException
  • 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-14T20:54:31+00:00Added an answer on June 14, 2026 at 8:54 pm

    Because,

    Your ListView lv is NULL.

    You forgot to define ListView lv after setContentView(R.layout.test);

    You have to do something like,

    lv = (ListView) findViewById(R.id.<lisview_id_from_test.xml>);
    

    So remove lv = (ListView) findViewById(R.id.ListView); from onPostExecute()

    and put it before code line new MyAsyncTask().execute("http://....");.

    Reason:

    Actually what happen is,

    Before going to onPostExecute() of AsyncTask, The code line lv.setOnItemClickListener(new OnItemClickListener() {...} is executed and there the Object of Listview lv is NULL.

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

Sidebar

Related Questions

The project I'm working on is slightly more complicated but I made this simple
I made a simple graph to write MKV file. But I do not want
I made simple email in wordpress but it would only send email to the
hi i've got question i've made simple form with attachment input and i want
Visual Studio 2008 (vb.net) I made simple anivirus but when I make Full scan
I made a simple ball bouncing program with VC++. the goal of this program
I made a simple gallery, using this script to show the images: $rs =
Question is simple: should i use any type of sanitization when using PHPmailer class?
I made simple plugin and i would like to work this plugin only below
I have made simple and thin database layer to help me with normal operation.

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.