Good day.
I have an app that has one main activity which holds 3 containers. Every container has a fragment "injected" into it. Upon starting this main activity, it's forced that first container and fragment are showing, and other two are hidden. On button click, app moves to the second container holding another fragment, and so on.
And this works, it's going forward to the last container, and backwards to the first container with android back button.
Problem is, if I stop at the second fragment, and I try to go back to the first one, without activating the third one, app crashes with following error:
java.lang.NullPointerException at
pl.oke.arshop.activities.ARShopActivity.onBackPressed(ARShopActivity.java:155)
at android.app.Activity.onKeyUp(Activity.java:1895) at
android.view.KeyEvent.dispatch(KeyEvent.java:1281) at
android.app.Activity.dispatchKeyEvent(Activity.java:2075) at
android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2463) at
android.view.ViewRoot.handleMessage(ViewRoot.java:1752) ... etc
where ARShopActivity.java:155 is:
@Override
public void onBackPressed() {
if (isVirtualRoomOpened) {
isVirtualRoomOpened = false;
showFurnitureFragments();
} else if (isFurnitureFragmentOpened) {
isFurnitureFragmentOpened = false;
showMainFragment();
}
super.onBackPressed();
Log.d("Dab", " " + isVirtualRoomOpened + " "
+ isFurnitureFragmentOpened + " " + isMainFragmentOpened);
}
}
Any thoughts? Thank you.