Md Shahryar Raza
Md Shahryar Raza

Reputation: 21

Fragment Error: Incompatible Types Required: android.support.v4.app.Fragment, Found: package_name.app_name.Fragment_name

I got an incompatible type error for the below code:

class TabsPagerAdapter extends FragmentPagerAdapter {

public TabsPagerAdapter(FragmentManager fm) {
    super(fm);
}

@Override
public Fragment getItem(int i) {
    switch (i) {
        case 0:
            RequestsFragment requestFragment = new RequestsFragment();
            return requestFragment;
        case 1:
            ChatsFragment chatsFragment = new ChatsFragment();
            return chatsFragment;
        case 2:
            FriendsFragment friendsFragment = new FriendsFragment();
            return friendsFragment;
        default:
            return null;
    }
}
@Override
public int getCount () {
    return 3;
}

public CharSequence getPageTitle(int position) {
    switch (position) {
        case 0:
            return "Requests";
        case 1:
            return "Chats";
        case 2:
            return "Friends";
        default:
            return null;
    }
}
}

See the image below:

click here to see the screenshot

Can anyone please help me to get out from this error? And how to resolve it.

Upvotes: 1

Views: 3159

Answers (1)

Nabin Bhandari
Nabin Bhandari

Reputation: 16429

Make your class RequestsFragment extend the class Fragment from the package android.support.v4.app.

If you have already extended the Fragment class, check the import statements and make sure there is

import android.support.v4.app.Fragment;

and not

import android.app.Fragment;

Upvotes: 3

Related Questions