0

So here's the code:

private void selectItem(int position) {

        Fragment fragment = null;

        switch (position) {
            case 0:
                fragment = new HomeFragment();
                break;
            case 1:
                fragment = new DoctorFragment();
                break;
            case 2:
                fragment = new HospitalFragment();
                break;
            case 3:
                fragment = new SpecialClinicFragment();
                break;
            case 4:
                fragment = new PharmacyFragment();
                break;

            default:
                break;
        }

        if (fragment != null) {
            FragmentManager fragmentManager = getFragmentManager();


            //the parameter "fragment" in this line of code gives an error message.
            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();



            mDrawerList.setItemChecked(position, true);
            mDrawerList.setSelection(position);
            getActionBar().setTitle(mNavigationDrawerItemTitles[position]);
            mDrawerLayout.closeDrawer(mDrawerList);

        } else {
            Log.e("MainActivity", "Error in creating fragment");
        }

enter image description here

It seems like I haven't properly initialised fragment instance.

The error message was "Wrong 2nd argument type" but I'm pretty sure I put in the right parameter.

Chris Mikkelsen
  • 3,987
  • 9
  • 29
  • 41
  • Possible duplicate of [obj Fragment wrong 2nd argument type found 'Android.support.V4.app.Fragment.' required 'Android.app.Fragment'](http://stackoverflow.com/questions/30339524/obj-fragment-wrong-2nd-argument-type-found-android-support-v4-app-fragment-re) – George Mulligan May 11 '16 at 03:01

1 Answers1

0

Problem is not with the argument.You have used Fragment from android.support.v4 library but you are making transaction on android.app.fragment.

Solution:

import android.app.fragment instead of android.support.v4.fragment

Because you cannot mix up with support.v4 library and android.app.*

akhil Rao
  • 1,169
  • 7
  • 17