I'm trying to populate a `ListView` with an `ArrayList` from a `Fragment` in Android and it's not working out. I'm getting an error saying that `java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference`.

Where should I initialize the `ListView` in order for it to be ready for the `onActivityCreated` method? 

**Fragment.java**

```
    private static final String TAG = SystemConditionsFragment.class.getSimpleName();

    private OnFragmentInteractionListener mListener;

    private ListView lv;

    private ListAdapter adapter;

    private ArrayList<String> alerts;

    private ProgressDialog progDailog;

    public SystemConditionsFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment SystemConditionsFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static SystemConditionsFragment newInstance(String param1, String param2) {
        SystemConditionsFragment fragment = new SystemConditionsFragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_system_conditions, container, false);
    lv = (ListView) rootView.findViewById(R.id.listView);
    return rootView;
}

    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(Uri uri) {
        if (mListener != null) {
            mListener.onFragmentInteraction(uri);
        }
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnFragmentInteractionListener) {
            mListener = (OnFragmentInteractionListener) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }

    @Override
    public void onStart() {
        super.onStart();
        refresh();
    }
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void refresh() {

        progDailog = ProgressDialog.show(getActivity(), "Loading","Please wait...", true);
        progDailog.setCancelable(false);

        progDailog.dismiss();

        final ObjectMapper mapper = new ObjectMapper();
        mapper.registerModule(new JsonOrgModule());

        Log.d(TAG, "Requesting events data");
        VolleyUtils.makeJsonObjectRequest(getActivity().getApplicationContext(),
                "events",
                new VolleyResponseListener() {

                    @Override
                    public void onError(String message) {
                        Log.e(TAG, "Error requesting events: " + message);
                    }

                    @Override
                    public void onResponse(JSONObject response) {
                        Log.d(TAG, "Received events response " + response);

                        DataRestResponse<SysCondRecord> data = mapper.convertValue(
                                response,
                                new TypeReference<DataRestResponse<SysCondRecord>>() {});
                        // Group by timestamp
                        ImmutableMultimap<DateTime, SysCondRecord> indexedData =
                                Multimaps.index(data.getData(),
                                        new Function<SysCondRecord, DateTime>() {
                                            @Override
                                            public DateTime apply(SysCondRecord record) {
                                                return record.getTimeStamp();
                                            }
                                        });
                        alerts = new ArrayList<>();
                        final List<DateTime> timestamp = new ArrayList<>();
                        for (SysCondRecord record : data.getData()) {
                            timestamp.add(record.getTimeStamp());
                            alerts.add(record.getMessage());
                        }

                        adapter = new ArrayAdapter(getActivity(),R.layout.fragment_system_conditions, R.id.listView, alerts);

                        lv.setAdapter(adapter);
                    }
                });
    }

```

**fragment\_system\_conditions.xml**

```
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/listView"
    android:layout_below="@+id/sysCondView"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="36dp" />

```

**Edit**

I was in fact using wrong ID guys, my bad! But I seem to have made things worse...

```
FATAL EXCEPTION: main
Process: xx.xxx.com, PID: 26183

java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView

```