Dhruv Paul
Dhruv Paul

Reputation: 47

Getting error Required android.support.v4.app.Fragment

I'm getting this error

Required android.support.v4.app.Fragment

Found in in.ashirvad.dhruv.krust.EventFragment

public void displayView(int viewId) {

    Fragment fragment = null;
    String title = getString(R.string.app_name);

    switch (viewId) {
        case R.id.nav_about:
            fragment = new NewsFragment();
            title  = "News";

            break;
        case R.id.nav_events:
            fragment = new EventFragment();
            title = "Events";
            break;

    }

    if (fragment != null) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.replace(R.id.content_frame, fragment);
        ft.commit();
    }

    // set the toolbar title
    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle(title);
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);

}

P.S.- in.ashirvad.dhruv.krust is my package name

Upvotes: 0

Views: 2035

Answers (2)

xelvias.exe
xelvias.exe

Reputation: 45

Check whether the fragment class you have imported in this class is same as the Fragment class in EventFragment class

Android has a built in Fragment class in latest versions of sdk but support library is for older versions or for continuity so those are two different locations.

Upvotes: 0

Vahid Hashemi
Vahid Hashemi

Reputation: 5240

Please add libraries you've used in this class. My wild guess is you are using the standard Fragment library rather than the v4 one.

Upvotes: 1

Related Questions