-1
私のアプリケーションにrecyclerviewがあり、リストアイテムを押したときボトムシートダイアログが2つのボタンを持っています。 これは、アダプタボトムシート上のボタンでクリックリスナーを設定しようとしたときにNullPointerExceptionが発生しました
BottomSheetDialog offer_info_dialog;
RelativeLayout rel;
Button Yes,No;
View parentView;
@Override
public void onClick(View view) {
rel = (RelativeLayout) activity.findViewById(R.id.bottomsheet);
Yes = (Button) offer_info_dialog.findViewById(R.id.confirm_btn_on_info);
No = (Button) offer_info_dialog.findViewById(R.id.cancel_btn_on_info);
offer_info_dialog = new BottomSheetDialog(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
parentView = inflater.inflate(R.layout.offer_info_layout, null);
offer_info_dialog.setContentView(parentView);
((View) parentView.getParent()).setBackgroundColor(context.getResources().getColor(android.R.color.transparent));
offer_info_dialog.show();
rel.setVisibility(View.INVISIBLE);
Yes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MainActivity.removeCheatOfferMarkers(2);
}
});
No.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from((View) parentView.getParent());
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
});
offer_info_dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
rel.setVisibility(View.VISIBLE);
}
});
}
中のonClickメソッドであり、これは誤りです:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.support.design.widget.BottomSheetDialog.findViewById(int)' on a null object reference
[NullPointerExceptionがある何を、どのように私はそれを修正しますか?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix -それ) –