Reputation: 55
The error im getting is: Wrong 2nd arguement type. found: 'com.example.appname.MainmenuFragment', required: 'android.support.v4.app.Fragment' By the way I know a similar question has been asked but that case is slightly different because this code is written in MainmenuActivity which is an activity not a fragment and MainmenuFragment is a fragment as the name implies. It worked this morning. I've been exploring quite a lot today but ended up having this unusual error. Here is the code in which I am getting the error:
public class MainmenuActivity extends AppCompatActivity {
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
switch (item.getItemId()) {
case R.id.navigation_mainmenu:
transaction.replace(R.id.container, new MainmenuFragment()).commit();
return true;
}
return false;
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainmenu);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.container, new MainmenuFragment()).commit();
}}
the line
transaction.replace(R.id.container, new MainmenuFragment()).commit();
and
transaction.replace(R.id.container, new MainmenuFragment()).commit();
is where I am getting the error. To be honest if I try using other fragment files instead of Mainmenu_Fragment it works fine wierdly.
Upvotes: 0
Views: 1301
Reputation: 1618
The problem might be because of getSupportFragmentManager()
. Try changing it to getFragmentManager()
.
Upvotes: 1
Reputation: 4206
You are probably using android.app.Fragment
instead of android.support.v4.app.Fragment
in your MainmenuFragment
Upvotes: 1