我的片段中的Recyclerview給了我這個錯誤,但我無法弄清楚。關於這個問題有很多問題,但目前爲止他們都沒有解決我的問題。沒有附加適配器;跳過片段中的佈局錯誤
這裏是我的片段的一段代碼:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home, container, false);
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
initCollapsingToolbar();
RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getActivity(), 2);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.addItemDecoration(new GridSpacingItemDecoration(2, dpToPx(10), true));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(adapter);
prepareSectors();
try {
Glide.with(this).load(R.drawable.cover).into((ImageView) view.findViewById(R.id.backdrop));
} catch (Exception e) {
e.printStackTrace();
}
return view;
}
什麼是錯誤?發佈它 –
@SriMaharshiManchem我認爲錯誤很明顯: 'E/RecyclerView:沒有附加適配器;跳過佈局「 –
你確定你的'adapter!= null'嗎? –