我正在尝试使用Roman Nurik(https://github.com/romannurik/Android-WizardPager)构建的向导。
我正在片段中部署它,我收到此错误。 其中一个类将OnAttach调用到一个活动,然而,它被一个片段调用。
请帮忙
FATAL EXCEPTION: main
java.lang.ClassCastException: Activity must implement PageFragmentCallbacks
at sfam.ui.com.MultipleChoiceFragment.onAttach(MultipleChoiceFragment.java:100)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:788)
at android.app.FragmentManagerImpl.performPendingDeferredStart(FragmentManager.java:731)
at android.app.Fragment.setUserVisibleHint(Fragment.java:1012)
at android.support.v13.app.FragmentCompatICSMR1.setUserVisibleHint(FragmentCompatICSMR1.java:23)
at android.support.v13.app.FragmentCompat$ICSMR1FragmentCompatImpl.setUserVisibleHint(FragmentCompat.java:48)
at android.support.v13.app.FragmentCompat.setUserVisibleHint(FragmentCompat.java:76)
at android.support.v13.app.FragmentStatePagerAdapter.setPrimaryItem(FragmentStatePagerAdapter.java:156)
at sfam.com.SFASurveyForm$MyPagerAdapter.setPrimaryItem(SFASurveyForm.java:461)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1071)
at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441)
at android.view.View.measure(View.java:13011)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
at android.view.View.measure(View.java:13011)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
at android.view.View.measure(View.java:13011)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:762)
at android.view.View.measure(View.java:13011)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
at android.view.View.measure(View.java:13011)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
at android.view.View.measure(View.java:13011)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2163)
at android.view.View.measure(View.java:13011)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1091)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2505)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4945)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native
方法)
答案 0 :(得分:2)
它说Activity must implement PageFragmentCallbacks
?因此..让你的Activity实现PageFragmentCallbacks。
如果您有权访问WizardPager代码,则可以将onAttatch()
更改为使用getParentFragment()
而不是getActivity()
,从而让您的父片段处理实施PageFragmentCallbacks
的角色