title: When is adapter null in RecyclerView
body: <p>In this question <a href="https://stackoverflow.com/q/36264223/4293403">“RecyclerView: No Adapter attached; skipping layout” for recyclerview</a> I complained about having an "No adapter attached; skipping layout" error while using RecyclerView. Partly because I didn't get the solution to that problem, I went wild on Android Studio; opening classes etc. During that process I opened the RecyclerView class and I saw that the only condition where that error will display is when the adapter is null. I have initialized and attached the adapter. I have searched and searched Google; no solution.</p>
  
  <p>I don't understand, if I move the initialization and attaching to onCreate method, the app crashes altogether.</p>
  
  <p>My question now is: when is an adapter null in RecyclerView and what might be the solution to the problem?</p>
  
  <p>Please help a green developer; this is my first app.
  Any suggestion would be welcomed.</p>
  
  <p><strong>This part of the MainActivity.java</strong></p>
  
  <pre><code>//Creating Views
      private RecyclerView recyclerView;
      private RecyclerView.Adapter adapter;
      private RecyclerView.LayoutManager layoutManager;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          //Initializing Views
          recyclerView = (RecyclerView) findViewById(R.id.post_recycler);
          layoutManager = new LinearLayoutManager(this);
          recyclerView.setLayoutManager(layoutManager);
          //Adding adapter to recyclerview
          recyclerView.setAdapter(adapter);
  </code></pre>
  
  <p><strong><em>I have alse tried this:</em></strong> 
  <strong>MainActivity.java</strong></p>
  
  <pre><code>    //Creating Views
      private RecyclerView recyclerView;
      private RecyclerView.Adapter adapter;
      private RecyclerView.LayoutManager layoutManager;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          //Initializing Views
          recyclerView = (RecyclerView) findViewById(R.id.post_recycler);
          layoutManager = new LinearLayoutManager(this);
          recyclerView.setLayoutManager(layoutManager);
  
         @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      //Initializing Views
      recyclerView = (RecyclerView) findViewById(R.id.post_recycler);
      layoutManager = new LinearLayoutManager(this);
      recyclerView.setLayoutManager(layoutManager);
  
  
      //Initializing the postlist list
      mPostItemsList = new ArrayList&lt;&gt;();
  
      //Caling method to get data
      getData();
  
  //This method will get data from the web api
  private void getData(){
      //Showing progress dialog
      final ProgressDialog progressDialog = ProgressDialog.show(this, "Loading posts", "Please wait", false, false);
  
      //Creating a json request
      JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(ConfigPost.GET_URL,
              new Response.Listener&lt;JSONArray&gt;() {
                  @Override
                  public void onResponse(JSONArray response) {
                      //Dismissing the progress dialog
                      progressDialog.dismiss();
  
                      //calling method to parse json array
                      parseData(response);
  
                  }
              },
              new Response.ErrorListener() {
                  @Override
                  public void onErrorResponse(VolleyError error) {
  
                  }
              });
  
      //Creating request queue
      RequestQueue requestQueue = Volley.newRequestQueue(this);
  
      //Adding request to the queue
      requestQueue.add(jsonArrayRequest);
  }
  
  //This method will parse json data
  private void parseData(JSONArray array){
      for(int i = 0; i&lt;array.length(); i++) {
          PostItems postItem = new PostItems();
          JSONObject jsonObject = null;
          try {
              jsonObject = array.getJSONObject(i);
              postItem.setPost_image(jsonObject.getString(ConfigPost.TAG_POST_IMAGE));
              postItem.setPost_title(jsonObject.getString(ConfigPost.TAG_POST_TITLE));
              postItem.setPost_body(jsonObject.getString(ConfigPost.TAG_POST_BODY));
          } catch (JSONException w) {
              w.printStackTrace();
              //Toast.makeText(this, "Error in parsing Json", Toast.LENGTH_LONG).show();
          }
          mPostItemsList.add(postItem);
      }
  
      //Finally initialing the adapter
      adapter = new PostAdapter(mPostItemsList, this);
  
      //Adding adapter to recyclerview
      recyclerView.setAdapter(adapter);
      adapter.notifyDataSetChanged();
  }
  </code></pre>
  
  <p><strong>Adapter class</strong></p>
  
  <pre><code>public class PostAdapter extends RecyclerView.Adapter&lt;PostAdapter.ViewHolder&gt;{
  
      private ImageLoader mImageLoader;
      private Context mContext;
  
      //List of posts
      List&lt;PostItems&gt; mPostItems;
  
  
  
     public PostAdapter(List&lt;PostItems&gt; postItems, Context context) {
         super();
  
         //Getting all Posts
         this.mPostItems = postItems;
         this.mContext = context;
     }
  
      @Override
      public ViewHolder  onCreateViewHolder (ViewGroup parent, int viewType) {
          View v =  LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.post_summ, parent, false);
          ViewHolder viewHolder = new ViewHolder(v);
          return viewHolder;
      }
  
      @Override
      public void onBindViewHolder(ViewHolder holder, int position) {
  
        PostItems postList = mPostItems.get(position);
  
        mImageLoader = VolleyRequest.getInstance(mContext).getImageLoader();
        mImageLoader.get(postList.getPost_image(), ImageLoader.getImageListener(holder.postImage, R.mipmap.ic_launcher, android.R.drawable.ic_dialog_alert));
  
        holder.postImage.setImageUrl(postList.getPost_image(), mImageLoader);
        holder.postTitle.setText(postList.getPost_title());
        holder.postBody.setText(postList.getPost_body());
  
      }
  
  
      @Override
      public int getItemCount(){
          //Return the number of items in the data set
          return mPostItems.size();
      }
  
      class ViewHolder extends RecyclerView.ViewHolder {
          public NetworkImageView postImage;
          public TextView postTitle;
          public TextView postBody;
  
          public ViewHolder(View postView) {
              super(postView);
              postImage = (NetworkImageView) postView.findViewById(R.id.post_image);
              postTitle = (TextView) postView.findViewById(R.id.post_title);
              postBody = (TextView) postView.findViewById(R.id.post_body);
          }
      }
  }
  </code></pre>
  
  <p><strong>XML Layout</strong></p>
  
  <pre><code>&lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      tools:context="com.jadebyte.geekng.MainActivity"
      tools:showIn="@layout/app_bar_main"&gt;
  
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/post_recycler"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:scrollbars="vertical"/&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>