Android development error "'Scroller.computeScrollOffset()' on a null object reference"

     When using a custom control, you need to use Scroller.compterScrollOffset() to judge whether the sliding of the control is completed. Surprisingly, this error is reported to me:

      The error suggested me: Reference to a Scroller.compterScrollOffset() null object. I found the place to initialize Scroll again, as shown below:

       Then I thought about it again, it's not that the control needs findViewById, it just needs a new object. I wonder if the direction of thinking is wrong, then we can only consider it from mScroller.computeScrollOffset(). Only mScroller can refer to an empty object. computeScrollOffset() is simply to judge whether the View sliding is over. View? slide? , combined with the Logcat error message "referencing an empty object", could it be that the View was not found?

      Here are the three constructors in the custom control:

Context: Get the context, often used, needless to say.

AttributeSet: Check various information, and finally found that it is related to XML.

defStyleAttr: related to the system Theme

I was thinking that since AttributeSet is related to XML, should I create a new Scroller in the second one. After all, they are called in different ways, try

Check the logcat information, Ness, no error is reported.  .

Guess you like

Origin blog.csdn.net/qq_62079241/article/details/127111885