別のrecyclerviewアダプタ内からrecyclerviewを作成しようとしています。何かこのラインでコンソール出力を壊しているrv.setLayoutManager(new LinearLayoutManager(context))
コードが間違っていることは次のとおりです。RecyclerViewが生成されない
08-17 21:14:20.221 11999-11999/in.co.sd.app E/RecyclerView: No adapter attached; skipping layout
08-17 21:14:20.227 11999-11999/in.co.sd.app V/BoostFramework: BoostFramework() : mPerf = [email protected]
08-17 21:14:20.228 11999-11999/in.co.sd.app V/BoostFramework: BoostFramework() : mPerf = [email protected]
08-17 21:14:20.230 11999-11999/in.co.sd.app E/RecyclerView: No adapter attached; skipping layout
08-17 21:14:20.237 11999-11999/in.co.sd.app V/BoostFramework: BoostFramework() : mPerf = [email protected]
08-17 21:14:20.237 11999-11999/in.co.sd.app V/BoostFramework: BoostFramework() : mPerf = [email protected]
08-17 21:14:20.239 11999-11999/in.co.sd.app E/RecyclerView: No adapter attached; skipping layout
08-17 21:14:20.244 11999-11999/in.co.sd.app V/BoostFramework: BoostFramework() : mPerf = [email protected]
08-17 21:14:20.244 11999-11999/in.co.sd.app V/BoostFramework: BoostFramework() : mPerf = [email protected]
08-17 21:14:20.247 11999-11999/in.co.sd.app E/RecyclerView: No adapter attached; skipping layout
08-17 21:14:20.253 11999-11999/in.co.sd.app V/BoostFramework: BoostFramework() : mPerf = [email protected]
08-17 21:14:20.253 11999-11999/in.co.sd.app V/BoostFramework: BoostFramework() : mPerf = [email protected]
08-17 21:14:20.255 11999-11999/in.co.sd.app E/RecyclerView: No adapter attached; skipping layout
08-17 21:14:20.260 11999-11999/in.co.sd.app V/BoostFramework: BoostFramework() : mPerf = [email protected]
08-17 21:14:20.261 11999-11999/in.co.sd.app V/BoostFramework: BoostFramework() : mPerf = [email protected]
08-17 21:14:20.263 11999-11999/in.co.sd.app E/RecyclerView: No adapter attached; skipping layout
08-17 21:14:20.266 11999-11999/in.co.sd.app V/BoostFramework: BoostFramework() : mPerf = [email protected]
08-17 21:14:20.266 11999-11999/in.co.sd.app V/BoostFramework: BoostFramework() : mPerf = [email protected]
08-17 21:14:20.267 11999-11999/in.co.sd.app E/RecyclerView: No adapter attached; skipping layout
08-17 21:14:40.197 11999-11999/in.co.sd.app D/AndroidRuntime: Shutting down VM
--------- beginning of crash
08-17 21:14:40.198 11999-11999/in.co.sd.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: in.co.servicedeal.app, PID: 11999
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
at in.co.servicedeal.app.adapter.BrandAdapter$1.onClick(BrandAdapter.java:106)
at android.view.View.performClick(View.java:5207)
at android.view.View$PerformClick.run(View.java:21177)
at android.os.Handler.handleCallback(Handler.java:742)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5527)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
--------- beginning of system
08-17 21:14:40.201 11999-11999/in.co.sd.app E/MQSEventManagerDelegate: failed to get MQSService.
08-17 21:14:40.242 11999-11999/in.co.sd.app I/Process: Sending signal. PID: 11999 SIG: 9
アダプターコード
はpublic class BrandAdapter extends BaseAdapter {
private LayoutInflater layoutInflater;
private Context context;
private ArrayList<BrandBean> brandList;
private RecyclerView rv;
public BrandAdapter(final Context context, final ArrayList<BrandBean> brandList) {
this.context = context;
this.brandList = brandList;
}
@Override
public int getCount() {
return brandList.size();
}
@Override
public Object getItem(int i) {
return brandList.get(i).getId();
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(final int i, View view, ViewGroup viewGroup) {
layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (view == null) {
view = layoutInflater.inflate(R.layout.item_brand_service_grid, null);
//Grid Text
final TextView gridText = view.findViewById(R.id.brand_grid_text);
gridText.setText(brandList.get(i).getServiceType());
//Grid Arraw
final ImageView gridArrow = view.findViewById(R.id.brand_grid_arrow);
gridArrow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Grid Dropdown
rv = view.findViewById(R.id.recycler_view_SI);
rv.setLayoutManager(new LinearLayoutManager(context));
getProductDetailsByProductId(brandList.get(i).getId());
}
});
}
return view;
}
アイデアは、このレイアウトを達成することである。
空白にはrecyclerViewコンテンツが含まれます。
この行はnullオブジェクトを返します。_rv = view.findViewById(R.id.recycler_view_SI); _ –
はい、ログに表示されますが、理由はわかりません。その行のすぐ上にrecyclerViewをインスタンス化しました。 –
ViewHolderクラスはありますか?また、なぜRecyclerView.Adapterの代わりにBaseAdapterを拡張していますか? – Juan