I have 3 fragments being used in a viewpager.I'm using a FragmentPagerAdapter to switch between them. I get this error all the time and I can't figure out why.
android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment ... make sure class name exists, is public, and has an empty constructor that is public
Here's my getItem method. I have a static method to get the instance, but it still complains.
@Override
public Fragment getItem(int pos) {
if (SECTION_COUNT > 1){
switch(pos){
case RECENT_HISTREES:
return HistreesFragmentPhone.newInstance(HistreesViewType.Friends, accountId, userId);
case MY_HISTREES:
return HistreesFragmentPhone.newInstance(HistreesViewType.All, accountId, userId);
case DOWNLOADED_HISTREES:
return HistreesFragmentPhone.newInstance(HistreesViewType.Downloaded, accountId, userId);
}
}
return HistreesFragmentPhone.newInstance(HistreesViewType.All, accountId, userId);
}
This is my Fragment constructor.
public static HistreesFragmentPhone newInstance(HistreesViewType viewType, int accountId, int userId) {
HistreesFragmentPhone f = new HistreesFragmentPhone();
Bundle args = new Bundle();
args.putString("viewType", viewType.toString());
args.putInt("accountId", accountId);
args.putInt("userId", userId);
f.setArguments(args);
return f;
}