“'App name'意外退出”

时间:2014-03-07 18:08:22

标签: android android-fragments classcastexception

任何人都可以告诉我我的问题来自这个logcat报告,我正在尝试创建一个滑动选项卡视图,我是新手,我根本不理解这个输出?

03-07 18:04:37.992: E/AndroidRuntime(773): FATAL EXCEPTION: main
03-07 18:04:37.992: E/AndroidRuntime(773): java.lang.ClassCastException: com.learn2crack.tab.MainActivity@40ce99b0 must implement OnHeadlineSelectedListener
03-07 18:04:37.992: E/AndroidRuntime(773):  at com.learn2crack.tab.HeadlinesFragment.onAttach(HeadlinesFragment.java:68)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:883)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.support.v4.app.FragmentManagerImpl.performPendingDeferredStart(FragmentManager.java:823)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.support.v4.app.Fragment.setUserVisibleHint(Fragment.java:841)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.support.v4.app.FragmentStatePagerAdapter.setPrimaryItem(FragmentStatePagerAdapter.java:152)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.support.v4.view.ViewPager.populate(ViewPager.java:1066)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.view.View.measure(View.java:15518)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.view.View.measure(View.java:15518)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.view.View.measure(View.java:15518)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-07 18:04:37.992: E/AndroidRuntime(773):  at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.view.View.measure(View.java:15518)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.view.Choreographer.doCallbacks(Choreographer.java:562)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.view.Choreographer.doFrame(Choreographer.java:532)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.os.Handler.handleCallback(Handler.java:725)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.os.Handler.dispatchMessage(Handler.java:92)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.os.Looper.loop(Looper.java:137)
03-07 18:04:37.992: E/AndroidRuntime(773):  at android.app.ActivityThread.main(ActivityThread.java:5041)
03-07 18:04:37.992: E/AndroidRuntime(773):  at java.lang.reflect.Method.invokeNative(Native Method)
03-07 18:04:37.992: E/AndroidRuntime(773):  at java.lang.reflect.Method.invoke(Method.java:511)
03-07 18:04:37.992: E/AndroidRuntime(773):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-07 18:04:37.992: E/AndroidRuntime(773):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-07 18:04:37.992: E/AndroidRuntime(773):  at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

您的片段HeadlinesFragment似乎需要在调用活动(OnHeadlineSelectedListener中声明的MainActivity接口,但它不需要。在MainActivity中,您的类声明应该类似于:< / p>

public class MainActivity extends Activity implements OnHeadlineSelectedListener