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

前端 未结 10 2242
青春惊慌失措
青春惊慌失措 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:43

    While it is ugly and not good practice, the only thing I could get to reliably work is just catching the exception in dispatchDraw() like below:

    override fun dispatchDraw(canvas: Canvas?) {
            /*
             * We're doing this because of the below exception that is out of our control:
             * 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:4111)
             */
            try {
                super.dispatchDraw(canvas)
            } catch (e: NullPointerException) {
    
            }
        }
    

    Just make sure your desired behavior is working correctly and you're not breaking something else by doing this. Again, not ideal, but it's the only thing I could get to work and I'm absolutely sure in my case it's not breaking anything else.

    Peace to you :)

提交回复
热议问题