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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:01:28+00:00 2026-06-04T22:01:28+00:00

I am having an issue binding my JSON data Object to a listView fragment.

  • 0

I am having an issue binding my JSON data Object to a listView fragment. I’m getting an NPE at line 100 where I bind to my Simple Adapter. I have tried various ways about doing this but have been unsuccessful. According to the docs:

You must use ListFragment.setListAdapter() to associate the list with
an adapter. Do not directly call ListView.setAdapter() or else
important initialization will be skipped.

I’m sure that is my issue but I don’t know how to go about correcting my code. Below is the NPE and my activity. Please any help will be appreciated, esp some code example because I’m learning as I go….

threadid=1: thread exiting with uncaught exception (group=0x40a781f8)
FATAL EXCEPTION: main java.lang.NullPointerException at
android.widget.SimpleAdapter.(SimpleAdapter.java:85) at
com.andaero.app.NavigationListFragment$1.callback(NavigationListFragment.java:100)
at
com.andaero.app.NavigationListFragment$1.callback(NavigationListFragment.java:1)
at
com.androidquery.callback.AbstractAjaxCallback.callback(AbstractAjaxCallback.java:440)
at
com.androidquery.callback.AbstractAjaxCallback.afterWork(AbstractAjaxCallback.java:1010)
at
com.androidquery.callback.AbstractAjaxCallback.run(AbstractAjaxCallback.java:804)
at android.os.Handler.handleCallback(Handler.java:605) at
android.os.Handler.dispatchMessage(Handler.java:92) at
android.os.Looper.loop(Looper.java:137) at
android.app.ActivityThread.main(ActivityThread.java:4424) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:511) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554) at
dalvik.system.NativeStart.main(Native Method)

public class NavigationListFragment extends ListFragment {
    Context context;
    private Activity c;
    final AQuery aq = new AQuery(c);
    private static String url = "http://192.168.1.17/Andaero/php/regulatory_list.php";

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.listview, container, false);
        Log.i("NavigationListFragment", "ListView Inflated!!");
        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        // AsyncTasks.getJSONArrays(context);// asynchronous task for getting
        // JSONarray
        aq.ajax(url, JSONArray.class, new AjaxCallback<JSONArray>() {
            // JSON Node names
            private static final String TAG_ID = "_id";
            private static final String TAG_LABEL = "label";
            private static final String TAG_TITLE = "title";
            private static final String TAG_DISCR = "description";
            private static final String TAG_GO2URL = "gotoURL";

            public void callback(String url, JSONArray json, AjaxStatus status) {
                if (json != null) {
                    // NavigationListFragment.jsonListCallback(json);
                    Log.i("NavigationListFragment", "Caught JSON: " + json.toString());
                    // Hashmap for ListView
                    ArrayList<HashMap<String, String>> mList = new ArrayList<HashMap<String, String>>();
                    try {
                        // Parse the string to a JSON object
                        for (int i = 0; i < json.length(); i++) {
                            JSONObject json_data = json.getJSONObject(i);

                            // Storing each json item in variable
                            String id = json_data.getString(TAG_ID);
                            String label = json_data.getString(TAG_LABEL);
                            String title = json_data.getString(TAG_TITLE);
                            String description = json_data.getString(TAG_DISCR);
                            String gotoURL = json_data.getString(TAG_GO2URL);

                            // 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_LABEL, label);
                            map.put(TAG_TITLE, title);
                            map.put(TAG_DISCR, description);
                            map.put(TAG_GO2URL, gotoURL);

                            // adding HashList to ArrayList
                            mList.add(map);
                            Log.i("NavigationListFragment", "Hash: " + map);
                        }
                    } catch (JSONException e) {
                        Log.e("log_tag", "Error parsing data " + e.toString());
                    }

                    // create the list item mapping
                    String[] from = new String[] {TAG_LABEL, TAG_TITLE, TAG_DISCR, TAG_GO2URL};
                    int[] to = new int[] { R.id.listLabel, R.id.listTitle, R.id.listDiscription, R.id.dummy };

                    // Updating parsed JSON data into ListView
                    SimpleAdapter adapter = new SimpleAdapter(c, mList, R.layout.list_item, from, to);//<--NPE IS HERE
                    setListAdapter(adapter);

                    // selecting single ListView item
                    ListView lv = getListView();

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

                        public void onItemClick(AdapterView<?> parent, View view,
                                int position, long id) {
                            //TODO
                        }
                    });

                }
                // Log any network/JSON Errors
                switch (status.getCode()) {
                    case AjaxStatus.TRANSFORM_ERROR :
                        Log.i("GetJSONArray", "TRANSFORM_ERROR");
                        break;
                    case AjaxStatus.NETWORK_ERROR :
                        Log.i("GetJSONArray", "NETWORK_ERROR");
                        // TODO Create Alert Dialog
                    case AjaxStatus.AUTH_ERROR :
                        Log.i("GetJSONArray", "AUTH_ERROR");
                        break;
                }
            }
        });

    }
}
  • 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-04T22:01:29+00:00Added an answer on June 4, 2026 at 10:01 pm

    Unless you are omitting code you never assign the value of c or context.

    When calling

    SimpleAdapter adapter = new SimpleAdapter(c, mList, R.layout.list_item, from, to);
    

    You are passing in “c” which will always be null.

    switch “c” to getActivity() and the problem should go away

    Additionaly,

    final AQuery aq = new AQuery(c);
    

    You should initialize this once you know you have access to getActivity(). When a fragment is created it will not immediately have access to the activity until attach(..) is called.

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

Sidebar

Related Questions

I have been having some issues retrieving JSON data from a WCF service application
I am having an issue with two-way binding the SelectedItem of the ListPicker In
Really having an issue debugging this...the reason why is probably very simple but I'm
I'm having an issue when I try to bind a visibility property to a
I am having a data binding problem (a separate question), and normally when I
Is it possible to avoid having 'NULL' stings on the client when binding JSON
I'm having an issue binding the LIMIT part of an SQL query. This is
I'm having an issue with a binding that I'm trying to implement. It will
I'm using WPF/MVVM and am having a binding issue with a ComboBox - any
I'm currently having an issue with WP7's TimePicker, specifically with binding it to a

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.