Getting Null Pointer Excetion While Populating data into listview <p>Please go through the following code and help me out. The data from the url is getting parsed but I am unable to populate in to the list view.</p> <pre class="lang-java prettyprint-override"><code>public class HomeFragment extends Fragment { View rootView = null; private ListView myListView; private String[] strListView; private String[] categ; private TextView catName; private CustomAdapter myAdapter; private DownloadJson downloadJson; private int i; private AsyncTask task; private Thread thread; public HomeFragment() { } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_home, container, false); myListView = (ListView) rootView.findViewById(R.id.listview); new DownloadJson().execute(); // Inflate the layout for this fragment return rootView; } </code></pre> <p>This is the <code>callCustomAdapter</code> Function:</p> <pre class="lang-java prettyprint-override"><code>public void callCustomAdaper( Context context) { myAdapter = new CustomAdapter(context); myListView.setAdapter(myAdapter); myListView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { Log.v("Module Item Trigger", "Module item was triggerted"); /* Fragment customMapFragmentMapFragment = new MessagesFragment(); FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); fragmentManager.beginTransaction() .replace(R.id.container, customMapFragmentMapFragment) .addToBackStack(null) .commit();*/ } }); } </code></pre> <p>This class is json parser:</p> <pre class="lang-java prettyprint-override"><code> class DownloadJson extends AsyncTask { Activity context; ListView myListView; private ProgressDialog dialog = new ProgressDialog(getActivity()); public DownloadJson(Activity context, ListView myListView) { this.myListView = myListView; this.context = context; } public DownloadJson() { } @Override protected void onPreExecute() { this.dialog.setMessage("Please wait"); this.dialog.show(); } @Override protected void onCancelled() { super.onCancelled(); } @Override protected Object doInBackground(Object[] params) { String result = null; InputStream isr = null; String imageId = null; String ip = "http://ganarajsshetti.tk/mobileapp/selectjson.php/"; try { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(ip); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); isr = httpEntity.getContent(); } catch (Exception e) { Log.e("log_tag", "Error in http Connection" + e.toString()); } // converting response to string try { BufferedReader br = new BufferedReader(new InputStreamReader(isr)); StringBuilder sb = new StringBuilder(); String line = null; while ((line = br.readLine()) != null) { sb.append(line + "\n"); } isr.close(); result = sb.toString(); } catch (Exception e) { Log.e("log_tag", "Error in Converting Data" + e.toString()); } // parse JSON data try { JSONArray jsonArray = new JSONArray(result); strListView = new String[jsonArray.length()]; for (int i = 0; i &lt; jsonArray.length(); i++) { JSONArray json_data = jsonArray.getJSONArray(i); for (int j =0; j&lt; json_data.length();j++) { strListView[i] = json_data.getString(j); System.out.println("--------------" + json_data.getString(0)); } Log.e("ACK_tag", "DATA" + strListView[i]); } } catch (Exception e) { Log.e("log_tag", "Error in parsing Data" + e.toString()); } return null; } @Override protected void onPostExecute(Object o) { // ArrayAdapter objAdapter = new ArrayAdapter&lt;String&gt;(context,R.layout.list_item,R.id.Category,strListView); if (dialog.isShowing()) { dialog.dismiss(); } callCustomAdaper(context); } } </code></pre> <p>This is my <code>customAdapter</code> which extends base adapter:</p> <pre class="lang-java prettyprint-override"><code>public class CustomAdapter extends BaseAdapter { private Context context; public CustomAdapter(Context context) { this.context = context; } @Override public int getCount() { return strListView.length; } @Override public Object getItem(int i) { return strListView[i]; } @Override public long getItemId(int i) { return i; } @Override public View getView(int i, View convertview, ViewGroup viewGroup) { View row= null; if(convertview == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = inflater.inflate(R.layout.list_item, viewGroup, false); } else{ row= convertview; } catName=(TextView) row.findViewById(R.id.Category); catName.setText(categ[i]); return row; } public String[] getValues() { return strListView; } } </code></pre> <p>These are my Xml files:</p> <pre class="lang-xml prettyprint-override"><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="info.androidhive.materialdesign.activity.HomeFragment"&gt; &lt;ListView android:id="@+id/listview" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt; &lt;/ListView&gt; &lt;/RelativeLayout&gt; </code></pre> <p>This is other xml: </p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp" android:paddingLeft="10dp" android:paddingRight="10dp"&gt; &lt;TextView android:id="@+id/Category" android:layout_width="50dp" android:layout_height="50dp" android:gravity="center_horizontal" android:textStyle="bold"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>And this was the error that I am getting:</p> <blockquote> <p>java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference at info.androidhive.materialdesign.activity.HomeFragment$CustomAdapter.getView(HomeFragment.java:248)</p> </blockquote>