Android RecyclerView:未连接适配器;跳过布局错误

Android RecyclerView:未连接适配器;跳过布局错误,android,android-cardview,android-recyclerview,Android,Android Cardview,Android Recyclerview,关于这个错误,我引用了不少帖子,但没有一篇能够解决我的问题。我有一个片段,我在其中使用改装获得了我的值,如下所示: public class Tab extends Fragment { public String nlink; public RecyclerView recycler; public List<Initialise> item; public Adapter adapter; public Context mContext; public Tab(Context

关于这个错误,我引用了不少帖子,但没有一篇能够解决我的问题。我有一个片段,我在其中使用改装获得了我的值,如下所示:

public class Tab extends Fragment
{
public String nlink;
public RecyclerView recycler;
public List<Initialise> item;
public Adapter adapter;
public Context mContext;

public Tab(Context mContext)
{
    this.mContext=mContext;
}


@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
    View v= inflater.inflate(R.layout.tab_layout,container,false);
    item = new ArrayList<>();
    recycler=(RecyclerView)v.findViewById(R.id.recycler);
    recycler.setHasFixedSize(true);
    LinearLayoutManager llm = new LinearLayoutManager(getContext());
    llm.setOrientation(LinearLayoutManager.VERTICAL);
    recycler.setLayoutManager(llm);
    recycler.setItemAnimator(new DefaultItemAnimator());
    adapter = new Adapter(item,mContext);
    recycler.setAdapter(adapter);
    return v;
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
{
    super.onViewCreated(view, savedInstanceState);
    Bundle bundle=getArguments();
    nlink=bundle.getString("link");
    Retrofit adapter = new Retrofit.Builder()
            .baseUrl(ItemAdapter.ROOT_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    Service Serviceapi = adapter.create(Service.class);
    Serviceapi.getitem(nlink).enqueue(new Callback<Item>()
    {
        @Override
        public void onResponse(Call<Item> call, Response<Item> response)
        {
            for(int i=0;i<response.body().getitems().size();i++)
            {
                item.add(new Initialise(response.body().getitems().get(i).getTitle(),response.body().getitems().get(i).getDate(),response.body().getitems().get(i).getcount(),response.body().getitems().get(i).getImage()));
            }
            adapter.notifyDataSetChanged();
        }

        @Override
        public void onFailure(Call<Item> call, Throwable t)
        {

        }
    });
}
}
公共类选项卡扩展片段
{
公共字符串链接;
公共废物回收公司;
公共清单项目;
公共适配器;
公共语境;
公共选项卡(上下文mContext)
{
this.mContext=mContext;
}
@凌驾
创建视图时的公共视图(LayoutFlater充气机、@Nullable ViewGroup容器、@Nullable Bundle savedInstanceState)
{
视图v=充气机。充气(右侧布局。选项卡布局,容器,错误);
item=newarraylist();
回收商=(RecyclerView)v.findViewById(R.id.recycler);
回收商。setHasFixedSize(真);
LinearLayoutManager llm=新的LinearLayoutManager(getContext());
llm.设置方向(线性布局管理器.垂直);
回收商。setLayoutManager(llm);
setItemAnimator(新的DefaultItemAnimator());
适配器=新适配器(项目,mContext);
回收器。设置适配器(适配器);
返回v;
}
@凌驾
已创建视图上的公共void(视图,@Nullable Bundle savedInstanceState)
{
super.onViewCreated(视图,savedInstanceState);
Bundle=getArguments();
nlink=bundle.getString(“链接”);
改装适配器=新改装.Builder()
.baseUrl(ItemAdapter.ROOT\u URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
Serviceapi=adapter.create(Service.class);
Serviceapi.getitem(nlink).enqueue(新回调()
{
@凌驾
公共void onResponse(调用、响应)
{
对于(int i=0;i尝试编辑
onCreateViewHolder()
方法

View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.tab_layout,parent,false);
        Holder rcv = new Holder(layoutView,mContext);
        return rcv;

显示了什么错误?E/RecyclerView:未连接适配器;跳过布局从服务器获取记录并在
onCreate()中初始化ArrayList而不是在
onViewCreated()中
method。在您的代码中,适配器是用空的ArrayList初始化的。这就是问题所在什么是Initialise和NewsInitialise?检查构造函数和全局变量项?同时发布完整的堆栈trace@Amrut关于NewsInitialise,对不起,我现在编辑了这个问题。请检查。关于堆栈跟踪,这是我唯一的错误我得到了。一切看起来都很好。我应该在Holder类中传递上下文作为额外参数吗?在Holder类中获取上下文时,我应该为上下文分配什么?我尝试在Holder类中使用此.mContext分配mContext,但仍然得到相同的错误
View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.tab_layout,parent,false);
        Holder rcv = new Holder(layoutView,mContext);
        return rcv;