我在我的片段中使用了setMenuVisibility()方法。
@Override
public void setMenuVisibility(boolean menuVisible) {
super.setMenuVisibility(menuVisible);
if (menuVisible) {
Toast.makeText(Global.getGcontext(), "Hot",Toast.LENGTH_SHORT).show();
}}
我的项目中有3个片段,当我从fragment1移动到fragment3时 我收到这个错误:
11-28 17:54:26.678 3777-3777/ir.keeyow.alaki E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: ir.keeyow.alaki, PID: 3777
java.lang.NullPointerException
at ir.keeyow.alaki.ir.keeyow.alaki.app.HotAlakiFragment.setMenuVisibility(HotAlakiFragment.java:233)
at android.support.v4.app.FragmentStatePagerAdapter.setPrimaryItem(FragmentStatePagerAdapter.java:149)
at android.support.v4.view.ViewPager.populate(ViewPager.java:802)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:433)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:405)
at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:386)
at com.astuetz.viewpager.extensions.PagerSlidingTabStrip$2.onClick(PagerSlidingTabStrip.java:240)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)

问题是什么?