0

I have five fragments with the bottom navigation menu. Currently, when I am in the 'home' fragment (home - bottom menu) and if I hit that again it reloads the recyclerView. The main issue is that, if the user hits the home menu again when the recyclerView loading is in progress, the app crashes with the following error.

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.tradaxis.utils.MSPTextViewBold.setVisibility(int)' on a null object reference

which is pointing at the visibility of the views (EditText, RecyclerView, etc)

If there is any solution for the above issue, then that is what I need else, I was thinking to disable (non-clickable) the bottom navigation menu item (of that particular fragment, that is, the current fragment in which the user is in).

How can I do this?

Note: My recyclerView has to load data from the Firestore

Codist
  • 737
  • 8
  • 23
  • Please share the code so that its much easier to point you to the right direction – Hascher Aug 01 '21 at 22:27
  • There is a lot of code and I do not know which code actually causing the error. As I said in my question, the error pointing at the visibility of the view. But that is not causing the error. Now I tried to disable the menu with this code, ` val navBar: BottomNavigationView = requireActivity().findViewById(R.id.nav_view) navBar.menu[R.id.navigation_dashboard].isEnabled=false` but it didn't work. Can you check if this code is OK. – Codist Aug 01 '21 at 23:27
  • I think it's because the user clicks the menu item before the recyclerView is loaded data from the Firestore, I am not sure though. Is it possible? If that is the case I can at least disable the menu item until the data is fully loaded. In order to check that I need the code to disable the menu item. – Codist Aug 01 '21 at 23:28
  • Seems like a nasty hack to to try to disable various UI interactions to try and prevent this event from occurring instead of going to the source and fixing the bug. You’ll be playing whack-a-mole trying to stop every possible way of encountering the bug instead of just fixing the bug. I recommend looking at the stack trace and utilizing the debugger to figure out why it’s even possible for the NPE to occur. – Tenfour04 Aug 02 '21 at 00:18
  • You are right. I asked a question at https://stackoverflow.com/q/68559418/13935956 and, I think, if I get a solution for that then this issue will also be solved. It seems like, the error occurs, when I am trying to hide the recyclerView before it's attached (it takes time as I have to fetch data from the Firebase). – Codist Aug 02 '21 at 09:38

0 Answers0