1

I got the the error" No adapter attached; skipping layout" in the logcat. But there seems to be no problem while displaying it on my phone.i would like to know what is causing the error.

Thanks in Advance.

OnCreate method:

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_appbar);
    context=this;

    toolbar=(Toolbar) findViewById(R.id.app_bar);
    setSupportActionBar(toolbar);

    getSupportActionBar().setDisplayShowHomeEnabled(true);

    NavFragment drawerFragment = (NavFragment)
            getSupportFragmentManager().findFragmentById(R.id.nav_frag);
    drawerFragment.setUp(R.id.nav_frag, (DrawerLayout) findViewById(R.id.drawerLayout), toolbar);
    listEvents= new ArrayList<>();



    Parse.enableLocalDatastore(this);
    Parse.initialize(this, "xxxxxxxxxx", "xxxxxxxxxxx");

    //TEST PARSE

    ParseQuery<ParseObject> query = ParseQuery.getQuery("Test");
    //query.whereEqualTo("playerName", "Dan Stemkoski");
    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> eventList, ParseException e) {
            if (e == null) {
                Log.d("Events", "Retrieved " + eventList.size() + " Events");

                for (int i = 0; i < eventList.size(); i++) {

                    Events events = new Events();
                    events.setTitle((String) eventList.get(i).get("teststr"));
                    events.setId(String.valueOf(eventList.get(i).get("teststr")));
                    listEvents.add(events);
                }
                eventAdapter= new EventAdapter(context);
                eventAdapter.setEventList(listEvents);
                eventsList.setAdapter(eventAdapter);
            } else {
                Log.d("score", "Error: " + e.getMessage());
            }
        }
    });


    eventsList=(RecyclerView)findViewById(R.id.list_events);
    eventsList.setLayoutManager(new LinearLayoutManager(this));



}

EventAdapter:

public class EventAdapter extends RecyclerView.Adapter<EventAdapter.ViewHolderEvents> {
    private LayoutInflater layoutInflater;
    private ArrayList<Events> listEvents= new ArrayList<>();
    public EventAdapter(Context context){
        layoutInflater=LayoutInflater.from(context);
    }

    public void setEventList(ArrayList<Events> listEvents){
        this.listEvents=listEvents;
        notifyItemRangeChanged(0,listEvents.size());
    }

    @Override
    public ViewHolderEvents onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view=layoutInflater.inflate(R.layout.custom_event_row,viewGroup,false);
        ViewHolderEvents viewHolder =new ViewHolderEvents(view);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolderEvents viewHolderEvents, int i) {
        Events currentEvent= listEvents.get(i);
        viewHolderEvents.title.setText(currentEvent.getTitle());
        viewHolderEvents.id.setText(currentEvent.getId());

    }

    @Override
    public int getItemCount() {
        return listEvents.size();
    }

    static class ViewHolderEvents extends RecyclerView.ViewHolder{
        private TextView title;
        private TextView id;

        public ViewHolderEvents(View itemView) {
            super(itemView);
            title=(TextView)itemView.findViewById(R.id.title);
            id=(TextView)itemView.findViewById(R.id.description);
        }
    }

}

activity_main_appbar:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<include
    android:id="@+id/app_bar"
    layout="@layout/app_bar" />
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawerLayout"

    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v7.widget.RecyclerView
            android:id="@+id/list_events"
            android:layout_height="match_parent"
            android:layout_width="match_parent"/>

    </FrameLayout>
    <fragment
        android:id="@+id/nav_frag"
        android:layout_width="280dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_nav"
        android:name="com.squaredbytes.eventlane.NavFragment"
        tools:layout="@layout/fragment_nav" />

</android.support.v4.widget.DrawerLayout>

Logcat:

08-02 14:52:51.344  15877-15932/com.squaredbytes.eventlane I/OpenGLRenderer﹕ Initialized EGL, version 1.4
08-02 14:52:51.456  15877-15932/com.squaredbytes.eventlane D/OpenGLRenderer﹕ Enabling debug mode 0
08-02 14:52:51.486  15877-15877/com.squaredbytes.eventlane E/RecyclerView﹕ No adapter attached; skipping layout
08-02 14:52:51.615  15877-15877/com.squaredbytes.eventlane E/RecyclerView﹕ No adapter attached; skipping layout
08-02 14:52:53.521  15877-15877/com.squaredbytes.eventlane D/Events﹕ Retrieved 4 Events
08-02 14:57:41.831  15877-15888/com.squaredbytes.eventlane W/art﹕ Suspending all threads took: 8.652ms
S J
  • 426
  • 1
  • 7
  • 15
videoKK GK
  • 11
  • 1
  • 4
  • is your app crashing? if yes could you post detailed logcat report – Samir Aug 02 '15 at 10:11
  • its not crashing. but i am worried seeing "No adapter attached; skipping layout" in logcat.. can you explain the reason behind it.. – videoKK GK Aug 02 '15 at 10:26

2 Answers2

1

It is because you are attaching the adapter to the RecyclerView later. You can set empty adapter at first and then populate the data to the adapter later when data is fetched.

You can look at SH.'s answer here for reference.

Community
  • 1
  • 1
Samir
  • 3,139
  • 2
  • 17
  • 24
0

I had this same exact problem and tried all answers on SO about it. Then I went to lunch and turn ON back my pc. And that error didn't appear anymore. Maybe restarting PC might solve it?

CommonSenseCode
  • 23,522
  • 33
  • 131
  • 186