title: How can I put the data to RecyclerView from okhttp and Asynctask
body: <p>I've get some Json data from server by okhttp ,and I want to show them in a 
   recycleview inside of a fragment using a custom adapter and receiving the following error. </p>
  
  <p>when I run this code,the logcat tell me the followeing msg:</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference
  </code></pre>
  
  <p>I print the <i>list</i> in the logcat ,it shows null.
  but I can get some json data from the IE.Do anyone help me,please?</p>
  
  <pre><code>public class customer extends AppCompatActivity {
  
  private static final String TAG = "MyDebug______ " ;
  private RecyclerView cutomerRecyclerView;
  private customerAdapter mAdapter;
  private ArrayList&lt;custModal&gt; list;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_customer);
      Toolbar toolbar = (Toolbar)findViewById(R.id.custom_toolbar);
      setSupportActionBar(toolbar);
  
      new getHttpData().execute();
      Log.d(TAG, "the list is :" +list);
       mAdapter = new customerAdapter(this,list);
      cutomerRecyclerView = (RecyclerView)findViewById(R.id.customer_list);
      cutomerRecyclerView.setLayoutManager(new LinearLayoutManager(this));
      cutomerRecyclerView.setAdapter(mAdapter);
      cutomerRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration(){
          @Override
          public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state){
              super.onDraw(c,parent,state);
              c.drawColor(R.color.colorDevider);
          }
          @Override
          public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
              super.onDrawOver(c, parent, state);
          }
          @Override
          public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
              super.getItemOffsets(outRect, view, parent, state);
  
              outRect.offset(0,1);
          }
      });
  }
  
  
  public class customerAdapter extends RecyclerView.Adapter&lt;customerAdapter.customerViewHolder&gt;{
      private Context mcontext;
      private ArrayList&lt;custModal&gt; mlist;
     // private LayoutInflater inflater;
      class customerViewHolder extends RecyclerView.ViewHolder{
          private TextView name,mem,cust_id;
  
          public customerViewHolder(View view){
              super(view);
              cust_id = (TextView )view.findViewById(R.id.cust_id);
              name = (TextView)view.findViewById(R.id.cust_name);
              mem = (TextView)view.findViewById(R.id.cust_mem);
          }
      }
      public customerAdapter(Context context,ArrayList&lt;custModal&gt; list){
          this.mcontext = context;
          this.mlist = list;
      }
     @Override
     public customerViewHolder onCreateViewHolder(ViewGroup parent,int viewType){
         customerViewHolder holder = new customerViewHolder(LayoutInflater.from(
                 customer.this).inflate(R.layout.customer_item,parent,false));
         return holder;
     }
      @Override
      public void onBindViewHolder(customerViewHolder holder,int position){
          holder.cust_id.setText(mlist.get(position).getId());
          holder.name.setText(mlist.get(position).getName());
          holder.mem.setText(mlist.get(position).getMobiphone());
      }
      @Override
      public int getItemCount(){ return mlist.size();}
  
  
  }
  </code></pre>
  
  <p>class custModal {</p>
  
  <pre><code>    private String id;
      private String name;
      private String gender;
      private String mobiphone;
      private String creat_time;
      public void setId(String id) {
          this.id = id;
      }
      public String getId() {
          return id;
      }
  
      public void setName(String name) {
          this.name = name;
      }
      public String getName() {
          return name;
      }
  
      public void setGender(String gender) {
          this.gender = gender;
      }
      public String getGender() {
          return gender;
      }
  
      public void setMobiphone(String mobiphone) {
          this.mobiphone = mobiphone;
      }
      public String getMobiphone() {
          return mobiphone;
      }
  
      public void setCreat_time(String creat_time) {
          this.creat_time = creat_time;
      }
      public String getCreat_time() {
          return creat_time;
      }
  
  }
  
  
  
  public class getHttpData extends AsyncTask&lt;String,Integer,ArrayList&lt;custModal&gt; &gt;{
      //private ArrayList&lt;custModal&gt; custlist;
  
      @Override
  
     // protected void onPreExecute(){}
  
      @Override
  
      protected ArrayList&lt;custModal&gt; doInBackground(String... params){
          String url = "http://aaaa.bbbbb.cn/index.php/mobi/customer/app_getlist";
  
          try{
              OkHttpClient client = new OkHttpClient();
              Request request = new Request.Builder()
                      .url(url)
                      .build();
              Response response = client.newCall(request).execute();
              String responseData = response.body().string();
              Log.d(TAG, "doInBackground: "+ responseData);
              if(responseData != null){
                  //return getCustFromJson(responseData);
                  Gson gson = new Gson();
                  ArrayList&lt;custModal&gt; custlist = gson.fromJson(responseData,
                          new TypeToken&lt;List&lt;custModal&gt;&gt;() {}.getType()
                  );
  
                  return custlist;
              }else{
                  return null;
              }
          }catch (IOException I){
              I.printStackTrace();
          }
  
          return null;
      }
      @Override
  
      protected  void onPostExecute(ArrayList&lt;custModal&gt; custlist){
          if(!custlist.isEmpty()){
              super.onPostExecute(custlist);
              list = custlist;
              mAdapter.notifyDataSetChanged();
          }
      }
  
  }
  </code></pre>
  
  <p>}</p>