最近碰到一个错误,所有日志如下
# main(1)
java.lang.NullPointerException
Attempt to read from field 'int android.view.View.mViewFlags' on a null object reference
解析
原始
1
android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3697)
2
android.view.View.updateDisplayListIfDirty(View.java:16182)
3
android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:648)
4
android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:654)
5
android.view.ThreadedRenderer.draw(ThreadedRenderer.java:762)
6
android.view.ViewRootImpl.draw(ViewRootImpl.java:2800)
7
android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2608)
8
android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2215)
9
android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1254)
10
android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6343)
11
android.view.Choreographer$CallbackRecord.run(Choreographer.java:874)
12
android.view.Choreographer.doCallbacks(Choreographer.java:686)
13
android.view.Choreographer.doFrame(Choreographer.java:621)
14
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860)
15
android.os.Handler.handleCallback(Handler.java:751)
16
android.os.Handler.dispatchMessage(Handler.java:95)
17
android.os.Looper.loop(Looper.java:154)
18
android.app.ActivityThread.main(ActivityThread.java:6119)
19
java.lang.reflect.Method.invoke(Native Method)
20
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
21
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
并没有报在我们自己写代码里面,提示就一个空指针,真的无从下手,最后弄了一个方法居然解决了,但不知其原理,这里做个记录,路过的大神不吝赐教下小弟了
解决方法如下:
new Handler().post(new Runnable() {
@Override
public void run() {
((ViewGroup) mGuideView.getParent()).removeView(mGuideView);
}
});
用一个handler对象把这句代码post下,把消息装入消息队列,其实都是在主线程里面的进行的,但是就不报错了,或许跟消息队列有关吧