Binary XML file line Error inflating class android.support.v7.widget.cardview
在cardview 搭配reclyerView的时候遇到这个错误。并没有改动xml文件。突然直接就报错,很蒙蔽。
网上说是布局的问题,比如findviewbyid并没有这个id或者setcontentview的问题。
最后在知道错在这里
LinearLayoutManager(mrecFragmnet.recyclerView.getApplicationContext()
/**
一定不要用getApllicationContext(),要用recyclerView.getContext()。这个一个找了很久的bug
**/));
homeadpter holder=new homeadpter(mrecFragmnet.recyclerView.getApplicationContext(),arrayList);
mrecFragmnet.recyclerView.setAdapter(holder);
报错的是cardview,因为cardview是reclyerView的itms,而reclyerView的context是getApplicationContext()是一个null
所以要改成getcontext()
arrayList = response.body().getNewslist();
mrecFragmnet.recyclerView.setLayoutManager(new LinearLayoutManager(mrecFragmnet.recyclerView.getContext()
/**
一定不要用getApllicationContext(),要用recyclerView.getContext()。这个一个找了很久的bug
**/));
homeadpter holder=new homeadpter(mrecFragmnet.recyclerView.getContext(),arrayList);
mrecFragmnet.recyclerView.setAdapter(holder);