8

我有一个错误:

03-01 11:20:43.453: E/AndroidRuntime(31235): java.lang.RuntimeException: Error receiving broadcast Intent { act=com.qz.Blaze.ServiceStarted flg=0x10 } in com.qz.Blaze.$ServiceStartedReceiver@423540f0
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:766)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.os.Handler.handleCallback(Handler.java:615)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.os.Looper.loop(Looper.java:137)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.app.ActivityThread.main(ActivityThread.java:4921)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at java.lang.reflect.Method.invokeNative(Native Method)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at java.lang.reflect.Method.invoke(Method.java:511)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at dalvik.system.NativeStart.main(Native Method)
03-01 11:20:43.453: E/AndroidRuntime(31235): Caused by: java.lang.IllegalStateException: Recursive entry to executePendingTransactions
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.view.ViewPager.populate(ViewPager.java:1011)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:522)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:494)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:475)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at com.qz.Blaze.Fragment.onCreateView(Fragment.java:53)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.view.ViewPager.populate(ViewPager.java:1011)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.view.ViewPager.populate(ViewPager.java:880)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:433)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at com.qz.XXX.XXXX.Init(.java:588)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at com.qz.Blaze..access$3(.java:546)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at com.qz.Blaze.$ServiceStartedReceiver.onReceive(.java:2416)
03-01 11:20:43.453: E/AndroidRuntime(31235):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:756)
03-01 11:20:43.453: E/AndroidRuntime(31235):    ... 9 more

MyActivity.m_oPager.setCurrentItem(iCurrentView);我的活动中与下面的适配器相关的行中:

public class FragmentPagerAdapter extends FragmentPagerAdapter
    {
        final int PAGE_COUNT_LOGGED_IN = 5;
        final int PAGE_COUNT_LOGGED_OUT = 2;
        TextView oTextView = null;
        LayoutInflater inflater = null;
        PagerTabStrip m_oPageTabStrip = null;
        String m_strTab = null;
        String[] m_strArray = null;     
        Context m_oContext = null;

        /** Constructor of the class */
        public FragmentPagerAdapter (Context context, FragmentManager oFragmentManager) 
        {
            super (oFragmentManager);
            m_oContext = context;
        }


        /** This method will be invoked when a page is requested to create */
        @Override
        public Fragment getItem(int arg0) 
        {       
            Fragment myFragment = new Fragment ();
            Bundle data = new Bundle();
            data.putInt("current_page", arg0+1);
            myFragment.setArguments(data);
            return myFragment;
        }

        /** Returns the number of pages */
        @Override
        public int getCount() 
        {       
            if (Utility.m_bIsLoggedIn == true)
            {
                return PAGE_COUNT_LOGGED_IN;
            }
            else
            {
                return PAGE_COUNT_LOGGED_OUT;
            }
        }

        @Override
        public CharSequence getPageTitle(int position) 
        {
            String strText = " ";

            switch(position)
            {
            case 0:
                strText = "";
                break;
            case 1:
                strText = "";
                break;
            case 2:
                strText = "";
                break;
            case 3:
                strText = "";
                break;
            case 4:
                strText = "";
                break;
            }

             Spannable s = Spannable.Factory.getInstance().newSpannable(strText);
             Typeface tt = Typeface.createFromAsset(m_oContext.getAssets(), "fonts/fontinsansbolditalic.ttf");
             s.setSpan (new CustomTypefaceSpan ("", tt), 0, strText.length(),Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
            return s;
        }
    }  
4

2 回答 2

14

创建 FragmentPagerAdapter 时使用getChildFragmentManager() 。例如:

new FragmentPagerAdapter(getChildFragmentManager());
于 2013-05-21T21:56:53.707 回答
2

使用最新版本的支持库,因为旧版本的 supportLibrary 不允许嵌套片段。

于 2014-02-18T11:51:59.370 回答