I\'m getting an error in this part of code:
private void displayView(int position) {
// update the main content by replacing fragments
Fragment fragm
Try changing
import android.app.Fragment;
to
import android.support.v4.app.Fragment;
Use classes from that support lib for all other imports too. Also getSupportFragmentManager()
as mentioned in the other answer.
In your HomeFragment
class
replace:
import android.app.Fragment;
with:
import android.support.v4.app.Fragment;
In Android Studio 2.3 getSupportFragmentManager works with android.support.v4.app but android studio 3.1 you have to use getFragmentManager enter image description here
In my case i have changed line-1 with line-2
Line-1: import android.app.Fragment
;
Line-2: import android.support.v4.app.Fragment
;
Its working
This seems to be an import
problem.
When using getFragmentMangager()
, make sure that your Fragment
classes extend android.app.Fragment
class.
If by any chance you are using android.support.v4.app.Fragment
(see your imports), then you need to use getSupportFragmentManager()
instead
Hope it helps
you just have to import android.support.v4.app.Fragment; in the all the FragmentClass();. that's it.