0

Getting this error no adapter attached ; Skipping layout ,I'm getting data from DB and displaying it in recyclerview here attaching code where i'm setting adapter and in empty view ,i think this issue may cause because of visibility of recycleview i'm not sure please suggest ,here is my code for setting adapter and loader

Adapter

 mRecyclerView = (RecyclerView) findViewById(R.id.inboxChatList);
    emptyData = (LinearLayout)findViewById(R.id.emptyData);
    dataEmptyText = (TextView)findViewById(R.id.dataEmptyText);
    mRecyclerView.setItemAnimator(new FadeInAnimator());
    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);
    mShop=HomeActivity.getClaimedShop(mContext);
    if (mShop.mVerifiedId != null) {
        L.e("mShop.mVerifiedId",mShop.mVerifiedId);
        emptyData.setVisibility(View.GONE);
        if (mAdapter.getItemCount() == 0) {
            emptyData.setVisibility(View.VISIBLE);
            dataEmptyText.setText(R.string.text_empty_inbox);
        }
        // use a linear layout manager
        mRecyclerView.setLayoutManager(new org.solovyev.android.views.llm.LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        getSupportLoaderManager().initLoader(mRecentChatsCallback.hashCode(), null, mRecentChatsCallback);
        mAdapter = new InboxChatAdapter(mContext, null);
        mRecyclerView.setAdapter(mAdapter);

    }else{
        emptyData.setVisibility(View.VISIBLE);
        dataEmptyText.setText(R.string.not_verified);
    }

Loader details

 private class RecentChatCallback implements LoaderManager.LoaderCallbacks<RecentChatLoader.Result> {
        boolean otpFlag = true;


        @Override
        public Loader<RecentChatLoader.Result> onCreateLoader(int id, Bundle args) {

            return new RecentChatLoader(mContext);
        }

        @Override
        public void onLoadFinished(Loader<RecentChatLoader.Result> loader, RecentChatLoader.Result data) {
            mAdapter.changeCursor(data.cursor);
            if(data.cursor.getCount()== 0){
                emptyData.setVisibility(View.VISIBLE);
                dataEmptyText.setText(R.string.text_empty_inbox);
                mRecyclerView.setVisibility(View.INVISIBLE);
            }else{
                mRecyclerView.setVisibility(View.VISIBLE);
                emptyData.setVisibility(View.GONE);
            }

        }

        @Override
        public void onLoaderReset(Loader<RecentChatLoader.Result> loader) {
            mAdapter.changeCursor(null);

        }


    }
}
sri
  • 73
  • 1
  • 11

2 Answers2

0

Two things to keep in mind here:

  1. When you set adapter to your recyclerview without any data in it then you will find this issue. (In your case you are passing null as data to your adapter before binding adapter with recyclerview.)
  2. It's just a warning so you can ignore this.
Irfan Raza
  • 2,859
  • 1
  • 22
  • 29
0

It happens because you don't set and adapter in 'else'. In general you see this error because the adapter is null:

void dispatchLayout() {
if(this.mAdapter == null) {
    Log.e("RecyclerView", "No adapter attached; skipping layout");
} else if(this.mLayout == null) {
    Log.e("RecyclerView", "No layout manager attached; skipping layout");
} else {

Also check that you are setting the adapter during onCreate. Here are a few similar questions: link1, link2

Community
  • 1
  • 1
Georgy
  • 364
  • 2
  • 14