0

I have a fragment that extends BottomSheetDialogFragment. I'm getting this error while running the app. I this the problem is in: mContext = getActivity().getApplicationContext(); I tried to replace it with mContext = getActivity(); but again it is showing the error.

It is the error: enter image description here

And this is the code:

public class FragmentBottomSheetDialogFull extends BottomSheetDialogFragment {
 @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
        final View view = View.inflate(getContext(), R.layout.aa, null);

        dialog.setContentView(view);
        mBehavior = BottomSheetBehavior.from((View) view.getParent());
        mBehavior.setPeekHeight(BottomSheetBehavior.PEEK_HEIGHT_AUTO);

        app_bar_layout = (AppBarLayout) view.findViewById(R.id.app_bar_layout);
        lyt_profile = (LinearLayout) view.findViewById(R.id.lyt_profile);

        mSoundCheckBox = view.findViewById(R.id.sound_checkbox);
        mVibrationCheckBox = view.findViewById(R.id.vibration_checkbox);
        populateSoundContents();
        populateVibrationContents();

        mContext = getActivity().getApplicationContext();
        AppController.currentActivity = getActivity();

        ((TextView) view.findViewById(R.id.name)).setText(R.string.setting_heading);
        ((TextView) view.findViewById(R.id.name_toolbar)).setText(R.string.setting_heading);
        ((View) view.findViewById(R.id.lyt_spacer)).setMinimumHeight(Utils.getScreenHeight() / 2);

        hideView(app_bar_layout);
return dialog;
    }
@Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }

private void switchSoundCheckbox() {
        isSoundOn = !isSoundOn;
        SettingsPreferences.setSoundEnableDisable(mContext, isSoundOn);
        populateSoundContents();
    }

    protected void populateSoundContents() {
        if (SettingsPreferences.getSoundEnableDisable(mContext)) {
            mSoundCheckBox.setChecked(true);
        } else {
            mSoundCheckBox.setChecked(false);
        }
        isSoundOn = SettingsPreferences.getSoundEnableDisable(mContext);
    }
public void viewClickHandler(View view) {
        switch (view.getId()) {
            case R.id.sound_checkbox:
                switchSoundCheckbox();
                break;
}
}
madan
  • 109
  • 1
  • 11

1 Answers1

1

Call populateSoundContents() after setting mCotext variable. Please change your code as below:

mContext = getActivity().getApplicationContext();
populateSoundContents();
populateVibrationContents();

    
Shalu T D
  • 3,921
  • 2
  • 26
  • 37
  • Oh!!! Thank you so much. can you help me with this too please? https://stackoverflow.com/questions/62887229/cant-zoom-the-webview-under-swipe-to-refresh – madan Jul 14 '20 at 02:44