I'm working on an Android app with a BottomNavigationBar and a FrameLayout. I have different fragments for every item of the BottomNavBar.
I'm trying to send datas from my MainActivity to one of them fragment using
Fragment2 fragmentClass = (Fragment2) getSupportFragmentManager().findFragmentById(R.id.fragLayout);
(fragLayout is the ID of my FrameLayout.
But when I run my project, I get the following error in the LogCat :
.ClassCastException: com.example.Fragment1 cannot be cast to com.example.Fragment2
What am I doing wrong? The Fragment2 is the active one when this code is running, so why does it say it cannot be cast to Fragment2 ?