Android ViewGroup crash: Attempt to read from field 'int android.view.View.mViewFlags' on a null object reference

前端 未结 10 2248
青春惊慌失措
青春惊慌失措 2020-12-08 00:15

We have found several cases for this kind of crashes reported by backend logging monitoring. It seems the crashes do not tie to particular UX failure. And from the reports,

10条回答
  •  渐次进展
    2020-12-08 00:20

    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

提交回复
热议问题