Android ViewGroup crashes: attempt to read from field 'int android.view.View.mViewFlags' by reference to null object

We found several cases for this type of failure that were reported during the monitoring of the backend log. It seems that the crashes are not related to UX failure. And from the reports there are no signs of how our own classes are involved (no signs of any names of our classes). Here is an example of typical crashes:

java.lang.NullPointerException: Attempt to read from field 'int android.view.View.mViewFlags' on a null object reference at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3357) at android.view.View.updateDisplayListIfDirty(View.java:14288) at android.view.View.getDisplayList(View.java:14315) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3549) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3528) at android.view.View.updateDisplayListIfDirty(View.java:14253) at android.view.View.getDisplayList(View.java:14315) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3549) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3528) at android.view.View.updateDisplayListIfDirty(View.java:14253) at android.view.View.getDisplayList(View.java:14315) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3549) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3528) at android.view.View.updateDisplayListIfDirty(View.java:14253) at android.view.View.getDisplayList(View.java:14315) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3549) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3528) at android.view.View.updateDisplayListIfDirty(View.java:14253) at android.view.View.getDisplayList(View.java:14315) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3549) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3528) at android.view.View.updateDisplayListIfDirty(View.java:14253) at android.view.View.getDisplayList(View.java:14315) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3549) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3528) at android.view.View.updateDisplayListIfDirty(View.java:14253) at android.view.View.getDisplayList(View.java:14315) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3549) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3528) at android.view.View.updateDisplayListIfDirty(View.java:14253) at android.view.View.getDisplayList(View.java:14315) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3549) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3528) at android.view.View.updateDisplayListIfDirty(View.java:14253) at android.view.View.getDisplayList(View.java:14315) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3549) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3528) at android.view.View.updateDisplayListIfDirty(View.java:14253) at android.view.View.getDisplayList(View.java:14315) at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:273) at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:279) at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:318) at android.view.ViewRootImpl.draw(ViewRootImpl.java:2561) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2377) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2007) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1086) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6453) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:846) at android.view.Choreographer.doCallbacks(Choreographer.java:647) at android.view.Choreographer.doFrame(Choreographer.java:601) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:829) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:927) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:713) 

Does anyone know if there is a related error registered in the Android code?

+56
java android viewgroup
Oct 20 '15 at 17:13
source share
7 answers

Possible Solution

I had the same problem. I install animation , and in onAnimationEnd I delete the object that was animated when problems arise. What I did was configure the asynchronous Runnable to wait 100 milliseconds after the animation stops before deleting the animated object:

previously animated this._loader object

 private void removeLoader() { final ContentContainer self = this; // "CustomContainer" needs to match the type of `this` Handler h = new Handler(); h.postAtTime(new Runnable() { @Override public void run() { MainActivity.instance.runOnUiThread(new Runnable() { @Override public void run() { try { if(self._loader == null) { // there is no loader. quit now while you still have the chance!! return; } while(self._loader.getParent() != null) { removeView(self._loader); } } catch(Exception e) { Crashlytics.logException(e); e.printStackTrace(); } self._loader = null; } }); } }, 100); } 

Greeting

+25
Feb 04 '16 at 15:29
source share

I had the same problem. I decided with Handler.

 new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { // remove fragment from here } }); 
+10
May 13 '16 at 2:44
source share

The problem is ViewGroup dispatchDraw() . This method tries to draw all ViewGroup . When the child is null , you get an exception that most likely comes from this line : if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) { (pay attention to mViewFlags ).

So the problem is that one of your views is somewhere incorrectly initialized. I'm afraid the best I can do.

+8
Jan 16 '16 at 16:01
source share

We also started to get this error. It was tracked before fragmentation of the animation, which is a problem. More specifically, the use of custom animations with replace() in a fragment transaction when the application is built against the Local Maven repository for Support Libraries rev> 26.

Possible Solution

Reduce the Local Maven repository for Support Libraries to 26. See here

+4
Mar 30 '16 at 15:38
source share

Possible Cause: I had the same problem. It turned out that this started to happen when I added code to change the view tree in the onDraw () call. To be specific, I removed the view with children in my derivative onDraw () when certain conditions were met. Now I think this is bad because the platform is trying to draw the views that I have now removed from the view tree. I solved the problem by sending a delete using Runnable after the onDraw () call was completed.

+2
Mar 30 '16 at 5:41
source share

Override the dispatchDraw method and place a try / catch block in it, for example:

 public void dispatchDraw(Canvas c) { try { super.dispatchDraw(c); return; } catch(Exception exception) { return; } } 
0
Dec 08 '17 at 15:35
source share

Although an exception is common, the calling source is unusual and occurs when you have so many dynamic representations . You can check by connecting inexpensive mobile phones with open Instagram. Sometimes scrolling on an Instagram page raises this exception. However, if you study this carefully, a hardware problem can become a problem. So handle (catch) the question.

0
Jun 11 '19 at 13:01
source share



All Articles