RecyclerView OnScrollListener.onScrolled空指针异常

bugly上的报错信息如下:

AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx
.recyclerview.widget.RecyclerView$OnScrollListener.onScrolled(androidx.recyclerview.widget
.RecyclerView, int, int)' on a null object reference

具体业务代码为:

public void setDate(InformationChannel channel){
            final RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListener()
            {
                @Override
                public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy)
                {
                    if (mLoadDataListener != null)
                    {
                        mLoadDataListener.backScrolled(FishView.this);
                    }
                }
            };
            this.mListView = new RecyclerView(context);
            this.mListView.setLayoutManager(new LinearLayoutManager(context, RecyclerView.VERTICAL, false));
            this.mListView.setAdapter(mChannelAdapter);
            this.mListView.addOnScrollListener(onScrollListener);
            this.mListView.setOverScrollMode(OVER_SCROLL_NEVER);
            this.mListView.setVerticalScrollBarEnabled(false);

            this.addView(this.mListView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

            this.setPullDownEnabled(true);
            this.setPullUpEnabled(true);
      
    }

目前分析可能是因为onScrollListener 定义在方法内部,方法结束之后,可能就被释放回收,所以导致空指针的产生。

你可能感兴趣的:(RecyclerView OnScrollListener.onScrolled空指针异常)