Marvin.H
Marvin.H

Reputation: 67

getSupportFragmentManager: incompatible types

I followed this tutorial: https://github.com/codepath/android_guides/wiki/Fragment-Navigation-Drawer

Now Im at this point:

// Insert the fragment by replacing any existing fragment
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit();

        // Highlight the selected item has been done by NavigationView
        menuItem.setChecked(true);
        // Set action bar title
        setTitle(menuItem.getTitle());
        // Close the navigation drawer
        mDrawer.closeDrawers();

My Problem is that this line..

FragmentManager fragmentManager = getSupportFragmentManager();

show me an error : incompatible types. Required android.app.FragmentManager Found: android.support.v4.app.FragmentManager.

I saw some posts but they doesn't work for me.

I extend my class with AppCompatActivity, tried FragmentActivity but this doesn't work.

If I change FragmentManager to android.support.v4.app.FragmentManager, the error disappear but then

fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit(); shows: Wrong 2nd argument type.Found:'android.app.Fragment',required'android.support.v4.app.Fragment'

Pls help me :/

Upvotes: 0

Views: 374

Answers (0)

Related Questions