No adapter attached; skipping layout [duplicate]
Asked Answered
W

2

11

logcat error : No adapter attached; skipping layout

I changed the context argument with getActivity(), but the app is still not running.

public class FragmentActivity extends Fragment {  
    private RecyclerView mRecyclerView;
    private CountryAdapter mAdapter;
    private LinearLayoutManager layoutManager;
    public FragmentActivity(){}
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.activity_main, container, false);
        mRecyclerView = (RecyclerView) rootView.findViewById(R.id.list);
        layoutManager = new LinearLayoutManager(getActivity());
        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.setAdapter(mAdapter);
        mAdapter = new CountryAdapter(CountryManager.getInstance().getCountries(), R.layout.card_layout, getActivity());
        return rootView;
    }
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }
}
Warden answered 13/2, 2015 at 23:37 Comment(0)
M
16

You didn't attach the adapter because you create it after you try to attach it:

mRecyclerView.setAdapter(mAdapter); // Here, mAdapter is null
mAdapter = new CountryAdapter(CountryManager.getInstance().getCountries(), R.layout.card_layout, getActivity());
Manlove answered 13/2, 2015 at 23:40 Comment(5)
thanks for the answer, im ataching my adapter now, but its still not showing my listWarden
CountryManager and CountryAdapter probably return wrong/empty data. They are not system classes so you would need to provide source.Manlove
Well they do return data when Im not using fragments, so I figured the problem lies in the fragment activityWarden
OK, maybe the fragment is displayed too small in the view hierarchy set in its host activity.Manlove
See hereManlove
W
4

In my case this problem occurs because there was a view on my layout which moved my list container and it was displayed too small

Witless answered 2/2, 2016 at 18:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.