I can\'t work out why my objFragment is giving me issues with the support manager, I\'m getting this error:
Error:(101, 17) error: no suitable method found
The problem is that there is a mismatch in fragments types between objFragment
and fragmentManager
. The first is from package android.support.v4.app
while the second is from the android.app
package.
See this answer here to know the difference between the two types of Fragments.
Now to fix the issue you have to handle your imports.
Either use import android.app.Fragment
instead of import android.support.v4.app.Fragment
Or do as Modge suggested; Update the main content of your app with a support Fragment manager like this: FragmentManager fragmentManager = getSupportFragmentManager()
. But then you also have to change the type of the FragmentManager itself; import android.app.FragmentManager
to import android.support.v4.app.FragmentManager;
Just change getFragmentManager()
to getSupportFragmentManager()
Below is the answer to a similar question I found while searching the internet. This worked for me, so I hope it will help you.
Menu_Fragment
is not inheriting fromandroid.support.v4.app.Fragment
. Presumably, it is inheriting fromandroid.app.Fragment
.There are two fragment implementations: the native one (e.g.,
android.app.Fragment
) and the backport (e.g.,android.support.v4.app.Fragment
). You need to be consistent. Your activity is aFragmentActivity
, which is part of the backport, so you need your fragments to inherit fromandroid.support.v4.app.Fragment
.
You tried to use the non support FragmentManager for your transaction. Change it to get the support one.
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, objFragment)
.commit();