I have two fragment class named SessionTab
and BillingTab
and i am trying to create instance of those class using
SessionTab sessionTab
Use one of this methods : findFragmentById()
and findFragmentByTag()
methods.
Reference : https://developer.android.com/reference/android/app/FragmentManager.html#findFragmentById(int)
Update :
ClassCastException
is invoked when you are not casting the appropriate classes to one another. In your case, Your FragmentManager
is returning different fragment than SessionTab
, so the exception is thrown.
If you use findFragmentById()
or findFragmentByTag()
, then it will return the fragment exactly what you want, and exception will not be thrown.