我是初学者程序员,我的应用程序有问题。它工作得很好,但是在点击菜单和滑动标签一段时间后它崩溃了。我只使用 ABS 作为外部库。如果还不够,请感觉树询问您需要的代码片段。这是崩溃的logcat:
07-28 00:17:57.461: E/AndroidRuntime(9542): FATAL EXCEPTION: main
07-28 00:17:57.461: E/AndroidRuntime(9542): java.lang.NullPointerException
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.support.v4.app.Fragment.setUserVisibleHint(Fragment.java:819)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.support.v4.app.FragmentPagerAdapter.setPrimaryItem(FragmentPagerAdapter.java:130)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.support.v4.view.ViewPager.populate(ViewPager.java:1066)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.support.v4.view.ViewPager.onInterceptTouchEvent(ViewPager.java:1890)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2060)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2418)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
07-28 00:17:57.461: E/AndroidRuntime(9542): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2139)
07-28 00:17:57.461: E/AndroidRuntime(9542): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1476)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.app.Activity.dispatchTouchEvent(Activity.java:2487)
07-28 00:17:57.461: E/AndroidRuntime(9542): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2087)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.View.dispatchPointerEvent(View.java:7535)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3415)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3347)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4456)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4434)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4538)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.os.MessageQueue.nativePollOnce(Native Method)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.os.MessageQueue.next(MessageQueue.java:125)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.os.Looper.loop(Looper.java:124)
07-28 00:17:57.461: E/AndroidRuntime(9542): at android.app.ActivityThread.main(ActivityThread.java:4921)
07-28 00:17:57.461: E/AndroidRuntime(9542): at java.lang.reflect.Method.invokeNative(Native Method)
07-28 00:17:57.461: E/AndroidRuntime(9542): at java.lang.reflect.Method.invoke(Method.java:511)
07-28 00:17:57.461: E/AndroidRuntime(9542): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
07-28 00:17:57.461: E/AndroidRuntime(9542): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
07-28 00:17:57.461: E/AndroidRuntime(9542): at dalvik.system.NativeStart.main(Native Method)
@编辑
我的应用程序再次崩溃,这里是异常点和新日志:
07-28 00:49:24.298: E/AndroidRuntime(11514): FATAL EXCEPTION: main
07-28 00:49:24.298: E/AndroidRuntime(11514): java.lang.NullPointerException
07-28 00:49:24.298: E/AndroidRuntime(11514): at android.support.v4.app.Fragment.setUserVisibleHint(Fragment.java:819)
07-28 00:49:24.298: E/AndroidRuntime(11514): at android.support.v4.app.FragmentPagerAdapter.setPrimaryItem(FragmentPagerAdapter.java:130)
07-28 00:49:24.298: E/AndroidRuntime(11514): at android.support.v4.view.ViewPager.populate(ViewPager.java:1066)
07-28 00:49:24.298: E/AndroidRuntime(11514): at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:550)
07-28 00:49:24.298: E/AndroidRuntime(11514): at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:509)
07-28 00:49:24.298: E/AndroidRuntime(11514): at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:490)
07-28 00:49:24.298: E/AndroidRuntime(11514): at pl.project.schedule.TabsAdapter.onTabSelected(TabsAdapter.java:72)
07-28 00:49:24.298: E/AndroidRuntime(11514): at com.actionbarsherlock.internal.app.ActionBarWrapper$TabWrapper.onTabSelected(ActionBarWrapper.java:356)
07-28 00:49:24.298: E/AndroidRuntime(11514): at com.android.internal.app.ActionBarImpl.selectTab(ActionBarImpl.java:587)
07-28 00:49:24.298: E/AndroidRuntime(11514): at com.android.internal.app.ActionBarImpl$TabImpl.select(ActionBarImpl.java:1084)
07-28 00:49:24.298: E/AndroidRuntime(11514): at com.android.internal.widget.ScrollingTabContainerView$TabClickListener.onClick(ScrollingTabContainerView.java:537)
07-28 00:49:24.298: E/AndroidRuntime(11514): at android.view.View.performClick(View.java:4232)
07-28 00:49:24.298: E/AndroidRuntime(11514): at android.view.View$PerformClick.run(View.java:17298)
07-28 00:49:24.298: E/AndroidRuntime(11514): at android.os.Handler.handleCallback(Handler.java:615)
07-28 00:49:24.298: E/AndroidRuntime(11514): at android.os.Handler.dispatchMessage(Handler.java:92)
07-28 00:49:24.298: E/AndroidRuntime(11514): at android.os.Looper.loop(Looper.java:137)
07-28 00:49:24.298: E/AndroidRuntime(11514): at android.app.ActivityThread.main(ActivityThread.java:4921)
07-28 00:49:24.298: E/AndroidRuntime(11514): at java.lang.reflect.Method.invokeNative(Native Method)
07-28 00:49:24.298: E/AndroidRuntime(11514): at java.lang.reflect.Method.invoke(Method.java:511)
07-28 00:49:24.298: E/AndroidRuntime(11514): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
07-28 00:49:24.298: E/AndroidRuntime(11514): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
07-28 00:49:24.298: E/AndroidRuntime(11514): at dalvik.system.NativeStart.main(Native Method)
--
07-28 00:49:24.298: E/AndroidRuntime(11514): at pl.project.schedule.TabsAdapter.onTabSelected(TabsAdapter.java:72)
public void onTabSelected(Tab tab, FragmentTransaction ft) {
mViewPager.setCurrentItem(tab.getPosition());
Log.v(TAG, "clicked");
Object tag = tab.getTag();
for (int i = 0; i < mTabs.size(); i++){
if (mTabs.get(i) == tag){
mViewPager.setCurrentItem(i);
}
}
}
--
07-28 00:49:24.298: E/AndroidRuntime(11514): at com.actionbarsherlock.internal.app.ActionBarWrapper$TabWrapper.onTabSelected(ActionBarWrapper.java:356)
public void onTabSelected(android.app.ActionBar.Tab tab, android.app.FragmentTransaction ft) {
if (mListener != null) {
if (mFragmentTransaction == null && mActivity instanceof FragmentActivity) {
mFragmentTransaction = ((FragmentActivity)mActivity).getSupportFragmentManager().beginTransaction()
.disallowAddToBackStack();
}
mListener.onTabSelected(this, mFragmentTransaction);
if (mFragmentTransaction != null) {
if (!mFragmentTransaction.isEmpty()) {
mFragmentTransaction.commit();
}
mFragmentTransaction = null;
}
}
}
--
07-28 00:49:24.298: E/AndroidRuntime(11514): at com.android.internal.app.ActionBarImpl.selectTab(ActionBarImpl.java:587)
07-28 00:49:24.298: E/AndroidRuntime(11514): at com.android.internal.app.ActionBarImpl$TabImpl.select(ActionBarImpl.java:1084)
void show(boolean markHiddenBeforeMode) {
if (mCurrentShowAnim != null) {
mCurrentShowAnim.end();
}
if (mContainerView.getVisibility() == View.VISIBLE) {
if (markHiddenBeforeMode) mWasHiddenBeforeMode = false;
return;
}
mContainerView.setVisibility(View.VISIBLE);
if (mShowHideAnimationEnabled) {
mContainerView.setAlpha(0);
AnimatorSet anim = new AnimatorSet();
AnimatorSet.Builder b = anim.play(ObjectAnimator.ofFloat(mContainerView, "alpha", 1));
if (mContentView != null) {
b.with(ObjectAnimator.ofFloat(mContentView, "translationY",
-mContainerView.getHeight(), 0));
mContainerView.setTranslationY(-mContainerView.getHeight());
b.with(ObjectAnimator.ofFloat(mContainerView, "translationY", 0));
}
if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) {
mSplitView.setAlpha(0);
mSplitView.setVisibility(View.VISIBLE);
b.with(ObjectAnimator.ofFloat(mSplitView, "alpha", 1));
}
anim.addListener(mShowListener);
mCurrentShowAnim = anim;
anim.start();
} else {
mContainerView.setAlpha(1);
mContainerView.setTranslationY(0);
mShowListener.onAnimationEnd(null);
}
}
--
07-28 00:49:24.298: E/AndroidRuntime(11514): at com.android.internal.widget.ScrollingTabContainerView$TabClickListener.onClick(ScrollingTabContainerView.java:537)
public void onAnimationCancel(Animator animation) {
mCanceled = true;
}