10

知道为什么会出现这种崩溃吗?跟踪只有本机代码,因此很难追踪。当我在 a中运行动画Fragment并且动画结束时我调用notifyDataSetChanged. FragmentStatePagerAdapter这个问题不是 100% 可重现的。

谢谢。

痕迹:

03-01 11:50:11.836: E/AndroidRuntime(21136): FATAL EXCEPTION: main
03-01 11:50:11.836: E/AndroidRuntime(21136): java.lang.NullPointerException
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3147)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12646)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12754)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3151)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12646)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12754)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3151)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12646)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12754)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3151)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12646)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12754)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3151)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12646)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12754)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3151)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12646)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12754)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3151)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12646)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12754)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3151)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12646)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12754)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3151)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12646)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12754)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3151)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12646)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12754)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3151)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12646)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.View.getDisplayList(View.java:12754)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1144)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2273)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2145)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1956)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1112)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4472)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.Choreographer.doCallbacks(Choreographer.java:555)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.Choreographer.doFrame(Choreographer.java:525)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.os.Handler.handleCallback(Handler.java:615)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.os.Looper.loop(Looper.java:137)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at android.app.ActivityThread.main(ActivityThread.java:4898)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at java.lang.reflect.Method.invokeNative(Native Method)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at java.lang.reflect.Method.invoke(Method.java:511)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-01 11:50:11.836: E/AndroidRuntime(21136):    at dalvik.system.NativeStart.main(Native Method)
4

2 回答 2

10

修复很简单,但不知道为什么有效。

AnimationListener'sonAnimationEnd回调中,我有一个触发的回调notifyDataSetChanged。我将该回调添加到Runnable并运行RunnablewithgetView().post

@Override
                public void onAnimationEnd(Animation animation) {

                    getView().post(new Runnable() {

                        @Override
                        public void run() {
                            // notifyDataSetChanged here
                        }
                    });
                }
于 2013-03-01T10:41:37.323 回答
0

很好的答案,但与 Android 的所有事情一样,这些答案很快就会过时。我现在会使用 runOnUiThread。我在一个基类中运行,动画师作为一个私有类。如需更深入地了解 runOnUiThread,请参阅
Android 基础知识:在 UI 线程中运行代码

    @Override
    public void onAnimationEnd(Animator animation) {

        //
        MyBaseActivity.this.runOnUiThread(new Runnable() {
            public void run() {
                Log.d("UI thread", "I am the UI thread");                    
            }
        });

    }
于 2019-04-17T15:51:25.923 回答