From cb0c8f9fcfe97487f1e6ca890994c2c5e2245607 Mon Sep 17 00:00:00 2001 From: Xtr126 Date: Sun, 12 Nov 2023 22:55:39 +0530 Subject: [PATCH] fix: check if binding is null E AndroidRuntime: java.lang.NullPointerException: Attempt to read from field 'androidx.recyclerview.widget.RecyclerView xtr.keymapper.databinding.FragmentProfilesViewBinding.profiles' on a null object reference at xtr.keymapper.profiles.ProfilesViewFragment.setAdapter(ProfilesViewFragment.java:66) --- .../xtr/keymapper/profiles/ProfilesViewFragment.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/xtr/keymapper/profiles/ProfilesViewFragment.java b/app/src/main/java/xtr/keymapper/profiles/ProfilesViewFragment.java index 8b4932b3..1bb23f35 100644 --- a/app/src/main/java/xtr/keymapper/profiles/ProfilesViewFragment.java +++ b/app/src/main/java/xtr/keymapper/profiles/ProfilesViewFragment.java @@ -6,15 +6,12 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.EditText; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.content.res.AppCompatResources; import androidx.fragment.app.Fragment; -import com.google.android.material.dialog.MaterialAlertDialogBuilder; - import xtr.keymapper.R; import xtr.keymapper.databinding.FragmentProfilesViewBinding; @@ -62,8 +59,10 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat } private void setAdapter() { - profilesViewAdapter = new ProfilesViewAdapter(getContext(), this::setAdapter); - binding.profiles.setAdapter(profilesViewAdapter); + if (binding != null) { + profilesViewAdapter = new ProfilesViewAdapter(getContext(), this::setAdapter); + binding.profiles.setAdapter(profilesViewAdapter); + } } @Override