I have a number of reports in Firebase Crashlytics
for the following crash,
Fatal Exception: java.lang.IllegalStateException: View null does not have a NavController set
at androidx.navigation.Navigation.findNavController(Navigation.java:84)
at com.***.splash.SplashFragment.lambda$checkLoggedInStatus$1$SplashFragment(SplashFragment.java:xxx)
at com.***.splash.-$$Lambda$SplashFragment$VafildstAQkrvymiO-AhxCqBHIE.run(lambda)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
This is my SplashFragment
public class SplashFragment extends DaggerFragment {
...
private View view;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_splash, container, false);
...
return view;
}
@Override
public void onResume() {
super.onResume();
checkLoggedInStatus();
}
private void checkLoggedInStatus() {
if (!splashViewModel.isLoggedIn()) {
new Handler().postDelayed(() - >
Navigation
.findNavController(view) // line xxx
.navigate(R.id.action_splashFragment_to_loginFragment), 1500);
} else {...}
}
...
@Override
public void onDestroy() {
view = null;
super.onDestroy();
}
}
I don't get this issue in my emulators or even in real devices for both DEBUG
and RELEASE
build types. So I'm having a hard time tracking it down. This happens to around 1.75%
live users. So my question is,
How does the
view
becomesnull
only for several users?
Can someone suggest a work around for this?