知道为什么会出现这种崩溃?跟踪只有本机代码,因此很难跟踪它。当我在Fragment
内运行动画时,三星Galaxy s3平台4.1.2会发生这种情况,当动画结束时,我会为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)
答案 0 :(得分:9)
修复很简单,但不知道为什么有效。
在AnimationListener
的{{1}}回调中,我有一个触发onAnimationEnd
的回调。我将该回调添加到notifyDataSetChanged
并使用Runnable
Runnable
getView().post
答案 1 :(得分:0)
很好的答案,但就像所有Android系统一样,这些答案的过时很快。
我现在将使用runOnUiThread。我在一个动画师作为私有类的基类中运行。有关runOnUiThread的更多信息,请参见
Android basics: running code in the UI thread
@Override
public void onAnimationEnd(Animator animation) {
//
MyBaseActivity.this.runOnUiThread(new Runnable() {
public void run() {
Log.d("UI thread", "I am the UI thread");
}
});
}