recyclerview 没有连接适配器;跳过布局 [英] recyclerview No adapter attached; skipping layout

查看:47
本文介绍了recyclerview 没有连接适配器;跳过布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚在我的代码中实现了RecyclerView,替换了ListView.

Just implemented RecyclerView in my code, replacing ListView.

一切正常.显示数据.

但是正在记录错误消息:

But error messages are being logged:

15:25:53.476 E/RecyclerView: No adapter attached; skipping layout

15:25:53.655 E/RecyclerView: No adapter attached; skipping layout

对于以下代码:

ArtistArrayAdapter adapter = new ArtistArrayAdapter(this, artists);
recyclerView = (RecyclerView) findViewById(R.id.cardList);
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));

如您所见,我已经为 RecyclerView 附加了一个适配器.那么为什么我总是收到这个错误?

As you can see I have attached an adapter for RecyclerView. So why do I keep getting this error?

我已经阅读了与同一问题相关的其他问题,但没有一个有帮助.

I have read other questions related to the same problem but none of them help.

推荐答案

你能确定你是从main"调用这些语句吗?延迟异步回调之外的线程(例如在 onCreate() 方法内).一旦我从延迟"中调用相同的语句方法.在我的例子中是 ResultCallback,我得到相同的消息.

Can you make sure that you are calling these statements from the "main" thread outside of a delayed asynchronous callback (for example inside the onCreate() method). As soon as I call the same statements from a "delayed" method. In my case a ResultCallback, I get the same message.

在我的 Fragment 中,从 ResultCallback 方法内部调用下面的代码会产生相同的消息.将代码移动到我的应用程序中的 onConnected() 方法后,消息消失了......

In my Fragment, calling the code below from inside a ResultCallback method produces the same message. After moving the code to the onConnected() method within my app, the message was gone...

LinearLayoutManager llm = new LinearLayoutManager(this);
llm.setOrientation(LinearLayoutManager.VERTICAL);
list.setLayoutManager(llm);
list.setAdapter( adapter );

这篇关于recyclerview 没有连接适配器;跳过布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆