我有一个slidingTabLayout,我一直得到这个RunTime异常?

时间:2016-02-07 18:50:30

标签: java android exception runtime

我已经设置了一个滑动标签布局,并且在标签之间切换时我不断收到此运行时异常。我不确定这意味着什么,有谁可以对这种情况有所了解?

FATAL EXCEPTION: main
                                                               java.lang.RuntimeException: com.athena.athena.MainActivitys.MainActivity@42988d90 must implement OnFragmentInteractionListener
                                                                   at com.athena.athena.MainActivitys.Tags.onAttach(Tags.java:84)
                                                                   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1019)
                                                                   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
                                                                   at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
                                                                   at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
                                                                   at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
                                                                   at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
                                                                   at android.support.v4.view.ViewPager.populate(ViewPager.java:1106)
                                                                   at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:552)
                                                                   at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:514)
                                                                   at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:495)
                                                                   at android.support.design.widget.TabLayout$ViewPagerOnTabSelectedListener.onTabSelected(TabLayout.java:1778)
                                                                   at android.support.design.widget.TabLayout.selectTab(TabLayout.java:871)
                                                                   at android.support.design.widget.TabLayout.selectTab(TabLayout.java:841)
                                                                   at android.support.design.widget.TabLayout$Tab.select(TabLayout.java:1115)
                                                                   at android.support.design.widget.TabLayout$1.onClick(TabLayout.java:665)
                                                                   at android.view.View.performClick(View.java:4475)
                                                                   at android.view.View$PerformClick.run(View.java:18786)
                                                                   at android.os.Handler.handleCallback(Handler.java:730)
                                                                   at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                   at android.os.Looper.loop(Looper.java:137)
                                                                   at android.app.ActivityThread.main(ActivityThread.java:5419)
                                                                   at java.lang.reflect.Method.invokeNative(Native Method)
                                                                   at java.lang.reflect.Method.invoke(Method.java:525)
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
                                                                   at dalvik.system.NativeStart.main(Native Method)



 public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
    public SectionsPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        //2 steps creating a fragment, create the fragment class and create the UI for it
        Fragment fragment = null;
        //we dont want it to return our place holder Fragment instead we want to switch bewtween 3
        //create a switch case based on the position applied or the fragment selected
        switch (position) {
            case HOME:
                fragment = Dashboard.newInstance("","");
                break;
            case TAGS:
                fragment = Tags.newInstance("","");
                break;
            case MY_RECENT:
                fragment = Recent.newInstance("","");
                break;
            case MY_POINTS:
                fragment = Points.newInstance("", "");
                break;
        }
        return fragment;
    }

    @Override
    public int getCount() {
        // Show 3 total pages.
        return 4;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0:
                return "Home";
            case 1:
                return "Points";
            case 2:
                return "Recent";
            case 3:
                return "Tags";
        }
        return null;
    }
}

}

我更新了问题以使其更具信息性。

1 个答案:

答案 0 :(得分:0)

正如您的例外所说:  java.lang.RuntimeException:com.athena.athena.MainActivitys.MainActivity@42988d90必须实现OnFragmentInteractionListener

请检查一下MainActivity是否正在实现OnFragmentInteractionListener类?