Android ViewGroup crash: Attempt to read from field 'int android.view.View.mViewFlags' on a null object reference
Possible Solution
I had this same issue. I setup an animation
and in onAnimationEnd
I was removing the object that had been animated which is when problems started. What I did was setup an asynchronous Runnable
to wait 100 milliseconds after the animation had stopped before removing the animated object:
the object previously animated is this._loader
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);}
Cheers
The problem is in the ViewGroup
's dispatchDraw()
method. This method tries to draw all the ViewGroup
's children. When a child is null
, you get an exception, which most likely comes from this line: if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) {
(notice the mViewFlags
).
So the problem is that one of your views, somewhere, is not properly initialized. I'm afraid that's the best I can do.