title: Android Volley - setAdapter in Fragment returns Null Pointer
body: <p><strong>CategoryFragment</strong>:</p>
  
  <pre><code>public class CategoryFragment extends Fragment {
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
  
          View rootView = inflater.inflate(R.layout.fragment_category, container,
                  false);
  
          va = new CategoryAdapter();
  
          listView = (ListView) rootView.findViewById(R.id.catListView);
          listView.setAdapter(va);
  
         ...
  
         JsonArrayRequest jr = new JsonArrayRequest(url, new Response.Listener&lt;JSONArray&gt;() {
              ...
  
         return rootView;
         }
  </code></pre>
  
  <p><strong>CategoryAdapter</strong>:</p>
  
  <pre><code>public class CategoryAdapter extends BaseAdapter {
  
      private ArrayList&lt;CategoryModel&gt; arrCategory;
      private LayoutInflater lf;
  
      @Override
      public int getCount() {
          return arrCategory.size();
      }
  
      @Override
      public Object getItem(int i) {
          return arrCategory.get(i);
      }
  
      @Override
      public long getItemId(int i) {
          return 0;
      }
  
      @Override
      public View getView(int i, View view, ViewGroup viewGroup) {
  
          ViewHolder vh;
  
          if (view == null) {
              vh = new ViewHolder();
              view = lf.inflate(R.layout.row_category_listview, null);
              vh.tvTitle = (TextView) view.findViewById(R.id.txtTitle);
              vh.tvCount = (TextView) view.findViewById(R.id.txtCount);
              view.setTag(vh);
          } else {
              vh = (ViewHolder) view.getTag();
          }
  
          CategoryModel nm = arrCategory.get(i);
          vh.tvTitle.setText(nm.getTitle());
          vh.tvCount.setText(nm.getCount());
  
          return view;
      }
  
      private class ViewHolder {
          TextView tvTitle;
          TextView tvCount;
      }
  
  }
      }
  }
  </code></pre>
  
  <p>I'm using Volley to parse JSON from an API. The main activity of my project here handles a navigation drawer, so I have to use <code>CategoryFragment</code> to display a listview of categories.</p>
  
  <p>However, by running the above code, I got this error:</p>
  
  <pre><code>01-08 17:43:37.950: E/AndroidRuntime(9897): java.lang.NullPointerException
  01-08 17:43:37.950: E/AndroidRuntime(9897):     at com.package.adapter.VolleyAdapter.getCount(VolleyAdapter.java:21)
  01-08 17:43:37.950: E/AndroidRuntime(9897):     at android.widget.ListView.setAdapter(ListView.java:462)
  01-08 17:43:37.950: E/AndroidRuntime(9897):     at com.package.fragment.CategoryFragment.onCreateView(CategoryFragment.java:54)
  </code></pre>
  
  <p>Anyone knows why it returns <code>nullpointerexception</code> when setting the adapter? I'm not really sure where the problem caused. Is it because it cannot find the fragment layout?</p>
  
  <p>If anything, please let me know.</p>