0

I have been trying to add "addonScrollListiner" in my kotlin code but it's giving me a null pointer exception. I have a fragment in which I have called API & populated data in my recycler view.

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                          savedInstanceState: Bundle?): View? {
    mRootView = inflater.inflate(R.layout.fragment_notifications, container, false)
    (activity as DifsBaseActivity?)!!.activityComponent.inject(this)
    ButterKnife.bind(this, mRootView)
    mPresenterNotification?.attachView(this)

    mPresenterNotification?.getNotifications()
    sweetUIErrorHandler = SweetUIErrorHandler(activity, mRootView)
    setHasOptionsMenu(true)
    setToolbarTitle("Notifications")
    return mRootView
}

The "getnotification" method is fetching data from api. In the "onnext" method of "getnotification" i am calling "displayNotifications"

override fun onNext(mResponse: Notifications?) {
                    mvpView!!.showProgressbar(false)
                    mvpView!!.displayNotifications(mResponse)
                }

This is what happing in "displayNotifications" method.

override fun displayNotifications(mObjResponse: Notifications?) {
    if (mObjResponse != null && mObjResponse.mListNotificaiton != null) {
        System.out.println("" + mObjResponse)
        if (mObjResponse.mListNotificaiton.size > 0) {
            hideOnErrorUI()
            mRvNotification.apply {
                mLayoutManager = LinearLayoutManager(activity);
                mLayoutManager!!.orientation = LinearLayoutManager.VERTICAL
                mRvNotification?.layoutManager = mLayoutManager
                mRvNotification?.setHasFixedSize(true)
                mAdapterNotification?.setGroups(mObjResponse.mListNotificaiton)
                mRvNotification.adapter = null;
                mRvNotification?.adapter = mAdapterNotification
                mAdapterNotification?.setItemClickListener { mView, position ->
                   if( mObjResponse.mListNotificaiton.get(position).objectType.trim().toLowerCase().equals("loan")){
                     //  mListener!!.loadLoan(4986, "Active")
                       mListener!!.loadGroup()


                   }else if(mObjResponse.mListNotificaiton.get(position).objectType.trim().toLowerCase().equals("client")){
                   //    mListener!!.loadClient( mObjResponse.mListNotificaiton.get(position).objectId, "Active")
                       mListener!!.loadGroup()


                   }


                }
            }
        } else {
            mRvNotification.adapter = null;
            showOnErrorUI()
        }
    } else {
        showOnErrorUI()
    }
}

I am not able to identify that which should I use "addonScrollListiner"

mRvNotification.addOnScrollListener(object : EndlessRecyclerViewScrollListener(mLayoutManager) {
                           override fun onLoadMore(page: Int, totalItemsCount: Int) {

                           }
                       })
FARS
  • 53
  • 10
Erum Malik
  • 641
  • 2
  • 6
  • 15
  • Could you edit your code to make it a minimal reproducible example? And also include the stack trace? – xjcl May 06 '21 at 11:23

0 Answers0