title: Android RecyclerView Does Not Update
body: <p>I am trying to add some values to my recyclerView adapter which I took from JSON. I am taking values correctly but it is giving this log:</p>
  
  <blockquote>
    <p>java.lang.NullPointerException:Attempt to invoke virtual method  'int
    java.util.ArrayList.size()' on a null object reference at:
    com.example.asus.drawer_app.MyAdapter.getItemCount(MyAdapter.java:55).</p>
  </blockquote>
  
  <p>My adapter is defined follow:</p>
  
  <pre><code>public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.ViewHolder&gt; {
  
     private ArrayList&lt;ItemData&gt; itemsData;
  
  public MyAdapter(ArrayList&lt;ItemData&gt; itemsData) {
      this.itemsData = itemsData;
      notifyDataSetChanged();
  
  }
  
  // Create new views (invoked by the layout manager)
  @Override
  public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
                                                 int viewType) {
      // create a new view
      View itemLayoutView = LayoutInflater.from(parent.getContext())
              .inflate(R.layout.fragment_news, null);
  
      // create ViewHolder
  
      ViewHolder viewHolder = new ViewHolder(itemLayoutView);
      return viewHolder;
  }
  
  // Replace the contents of a view (invoked by the layout manager)
  @Override
  public void onBindViewHolder(ViewHolder viewHolder, int position) {
  
      // - get data from your itemsData at this position
      // - replace the contents of the view with that itemsData
  
      viewHolder.txtViewDate.setText(itemsData.get(position).getDate());
      viewHolder.txtViewTitle.setText(itemsData.get(position).getTitle());
      viewHolder.txtViewDescription.setText(itemsData.get(position).getDescription());
      viewHolder.imgViewIcon.setText(itemsData.get(position).getImageUrl());
  
  
  
  }
  
  @Override
  public int getItemCount() {
      return itemsData.size();
  }
  
  // inner class to hold a reference to each item of RecyclerView
  public static class ViewHolder extends RecyclerView.ViewHolder {
  
      public TextView txtViewDate;
      public TextView txtViewTitle;
      public TextView txtViewDescription;
      public TextView imgViewIcon;
      public ViewHolder(View itemLayoutView) {
          super(itemLayoutView);
          txtViewTitle = (TextView) itemLayoutView.findViewById(R.id.item_title);
          txtViewDate = (TextView) itemLayoutView.findViewById(R.id.item_date);
          txtViewDescription = (TextView) itemLayoutView.findViewById(R.id.item_description);
          imgViewIcon = (TextView) itemLayoutView.findViewById(R.id.item_icon);
      }
  }
  
  
  
  // Return the size of your itemsData (invoked by the layout manager)
  
  }
  </code></pre>
  
  <p>And my fragment code is :</p>
  
  <pre><code>public class NewsFragment extends Fragment{
  
  String getItemsUrl="http://phptest.basarimobile.com/BoxFeed/ws.php?method=getItems&amp;token=test&amp;rssID=1&amp;lastID=190";
  ArrayList&lt;ItemData&gt; itemsData = null;
  
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setHasOptionsMenu(true);
  
      new JSONGetNews().execute();
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_news, container, false);
  
  
      RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
  
      // 2. set layoutManger
      recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
      // 3. create an adapter
  
      MyAdapter mAdapter = new MyAdapter(itemsData);
  
      // 4. set adapter
      recyclerView.setAdapter(mAdapter);
  
      // 5. set item animator to DefaultAnimator
      recyclerView.setItemAnimator(new DefaultItemAnimator());
  
      return rootView;
  }
  
  
  private class JSONGetNews extends AsyncTask&lt;String, String, JSONObject&gt; {
  
      private ProgressDialog pDialog;
  
      protected void onPreExecute() {
          super.onPreExecute();
          pDialog = new ProgressDialog(getActivity());
          pDialog.setMessage("Getting Data ...");
          pDialog.setIndeterminate(false);
          pDialog.setCancelable(true);
          pDialog.show();
  
      }
  
      @Override
      protected JSONObject doInBackground(String... args) {
          JSONParser jParser = new JSONParser();
  
  
          JSONObject json = jParser.getJSONFromUrl(getItemsUrl);
          return json;
      }
  
      protected void onPostExecute(JSONObject json) {
          pDialog.dismiss();
          try {
              // Getting JSON Array
              JSONArray titleArr = json.getJSONObject("data").getJSONArray("results");
  
              for (int i = 0; i &lt; titleArr.length(); i++) {
                  final JSONObject titleObj = titleArr.getJSONObject(i);
                  String title = titleObj.getString("title");
                  String description = titleObj.getString("description");
                  String imgUrl = titleObj.getString("img");
                  String date = titleObj.getString("date");
  
  
             itemsData.add(new ItemData(title, date, imgUrl, description));
  
              }
              }catch(JSONException e){
                  e.printStackTrace();
              }
          }
  
  
  }
  </code></pre>
  
  <p>I think itemsData is NULL. If it is null, how can I send it to adapter? And how can I update adapter?</p>
  
  <p>Thanks For Help.</p>