没有连接适配器; 跳过布局

logcat错误:没有附加适配器; 跳过布局

我用getActivity()更改了上下文参数,但该应用程序仍然没有运行。

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); } } 

Solutions Collecting From Web of "没有连接适配器; 跳过布局"

您没有附加适配器,因为您在尝试附加适配器后创build它​​:

 mRecyclerView.setAdapter(mAdapter); // Here, mAdapter is null mAdapter = new CountryAdapter(CountryManager.getInstance().getCountries(), R.layout.card_layout, getActivity()); 

在我的情况下,出现这个问题是因为我的布局中有一个视图,它移动了我的列表容器,显示得太小了