【问题标题】:What Should I Do with the error RecyclerView: No adapter attached; skipping layout我应该如何处理错误 RecyclerView: No adapter attach;跳过布局
【发布时间】:2019-07-19 00:19:39
【问题描述】:

我想从 mysql 服务器获取图像到回收站视图。当我运行我的应用程序时。我面临以下问题:

02-25 19:47:47.075 653-12579/? E/WakeLock:GCM_HB_ALARM 释放 没有匹配的获取! 02-25 19:47:53.241 69-403/?电子/快线: 没有收到预期的优先级提升 02-25 19:47:53.393 14523-14523/com.example.wiqarali.tourismapp E/RecyclerView:无适配器 随附的;跳过布局 02-25 19:47:53.466 14523-14523/com.example.wiqarali.tourismapp E/EventBus:不能 调度事件:类 com.example.wiqarali.tourismapp.serverclasses.GalleryEventBus 到 订阅类 com.example.wiqarali.tourismapp.GalleryActivity java.lang.NullPointerException:尝试调用虚拟方法'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' 在空对象引用上 在 com.example.wiqarali.tourismapp.GalleryActivity.onMessageEvent(GalleryActivity.java:131) 在 java.lang.reflect.Method.invoke(本机方法) 在 java.lang.reflect.Method.invoke(Method.java:372) 在 org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:507) 在 org.greenrobot.eventbus.EventBus.postToSubscription(EventBus.java:434) 在 org.greenrobot.eventbus.EventBus.postSingleEventForEventType(EventBus.java:411) 在 org.greenrobot.eventbus.EventBus.postSingleEvent(EventBus.java:384) 在 org.greenrobot.eventbus.EventBus.post(EventBus.java:265) 在 com.example.wiqarali.tourismapp.serverclasses.GetImages$1.onResponse(GetImages.java:59) 在 com.example.wiqarali.tourismapp.serverclasses.GetImages$1.onResponse(GetImages.java:37) 在 com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:82) 在 com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:29) 在 com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:102) 在 android.os.Handler.handleCallback(Handler.java:739) 在 android.os.Handler.dispatchMessage(Handler.java:95) 在 android.os.Looper.loop(Looper.java:135)

这是我的事件总线代码

@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(GalleryEventBus eventBus){
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    recyclerView_gallery.setLayoutManager(linearLayoutManager);
    recyclerView_gallery.setItemAnimator(new DefaultItemAnimator());
    GalleryAdapter adapter = new GalleryAdapter(this, eventBus.galleryList);
    recyclerView_gallery.setAdapter(adapter);
    adapter.notifyDataSetChanged();
}

【问题讨论】:

标签: android


【解决方案1】:

我遇到了和你一样的情况,我刚刚解决了它。 在我的情况下,当启动 RecyclerView 时,我只设置适配器,如果 data.size() > 0。然后当你收到事件并调用 notifyDataSetChanged() 导致该错误

  if (data.size() > 0) {
            rv.setLayoutManager(new GridLayoutManager(mContext, 3));
            rv.setItemAnimator(new DefaultItemAnimator());
            rv.setHasFixedSize(true);
            rv.setAdapter(myAdapter);
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-28
    • 2021-11-26
    • 2023-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-20
    • 2020-10-14
    相关资源
    最近更新 更多