0

我在 viewpager 中使用了 3 个片段。我正在使用 FragmentPagerAdapter 在它们之间切换。我一直收到这个错误,我不知道为什么。

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

这是我的 getItem 方法。我有一个静态方法来获取实例,但它仍然抱怨。

@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);
}

这是我的片段构造函数。

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;
}
4

0 回答 0