我有单击片段被替换的按钮单击侦听器,并在下一个片段上传递参数。 代码: -在roboelectric的单元测试期间获得空指针异常
Fragment fragment = new CustomList();
Bundle args = new Bundle();
args.putString("fragment", "Custom");
args.putSerializable("productBean", productBean);
fragment.setArguments(args);
fragmentManager = getActivity().getSupportFragmentManager();
fragmentTransaction = fragmentManager
.beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.slide_in, R.anim.slide_out, R.anim.slide_enter, R.anim.slide_exit);
fragmentTransaction.replace(R.id.container_body, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
写测试用例按钮点击: -
Button custom_btn = (Button) fragment.getView().findViewById(R.id.custom_btn);
custom_btn.performClick();
但在测试用例的执行,它显示空指针异常,当上CustomList getArguments()片段。
productsBean = (ProductsBean) getArguments().getSerializable("productsBean");
它的产品在代码中,错误地在这里粘贴了错误的代码。好。更多的建议 –