1. Download our Official Android App: Forums for Android!

Support “RecyclerView: No Adapter attached; skipping layout” for recyclerview

Discussion in 'Android Help' started by FonyCode, Mar 28, 2016.

  1. FonyCode

    FonyCode Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Mar 28, 2016

    Mar 28, 2016
    1
    0
    5
    Male
    I am a fledgling Android developer and I have managed to put together a RecyclerView. Using volley to parse json data containing blog posts, and using CardViews to populate the RecyclerView; I am getting this error "No adapter attched; skipping layout" when I run it on my device.

    Please note I have checked this question http://stackoverflow.com/q/29141729/4293403 but it didn't help.

    **This part of the MainActivity.java**


    //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);


    ***I have alse tried this:***
    **MainActivity.java**


    //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);

    //Left out some codes


    //Finally initialing the adapter
    adapter = new PostAdapter(mPostItemsList, this);

    //Adding adapter to recyclerview
    recyclerView.setAdapter(adapter);
    }

    **Adapter class**

    public class PostAdapter extends RecyclerView.Adapter<PostAdapter.ViewHolder>{

    private ImageLoader mImageLoader;
    private Context mContext;

    //List of posta
    List<PostItems> mPostItems;



    public PostAdapter(List<PostItems> postItems, Context context) {
    super();

    //Getting all superheroes
    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);
    }
    }
    }

    Any Idea what might be causing it?
     

    Advertisement

Share This Page

Loading...