Home » Android » required android.support.v4.app.fragment

required android.support.v4.app.fragment

Posted by: admin May 14, 2020 Leave a comment


i hope you can help me with this. i am new into android

i am trying to solve this problem but i couldnt

the problem when i declared this method

public void onNavigationDrawerItemSelected(int position) {

    // slide menue declaration
   Fragment fragment = null;
    switch (position) {
        case 0:
            fragment = new menu1_Fragment();
        case 1:
            fragment = new menu2_Fragment();
        case 2:
            fragment = new menu3_Fragment();


it give me an error saying required android.support.v4.app.fragment

How to&Answers:

Check your imports at the beginning of your classes. I guess there will be a import android.app.Fragment;. Change it to import android.support.v4.app.Fragment;. Maybe the error is caused by the menuX_Fragments which extend android.app.Fragment instead of the support fragment.

You can use import android.support.v4.app.Fragment for developing apps for lower android versions, fragments are introduced in Android 3.0.

Decide for one version of fragments and use it everywhere. I guess you mixed it up.