VideoPlayerManager icon indicating copy to clipboard operation
VideoPlayerManager copied to clipboard

NullPointerException onScroll

Open sarathkrrish opened this issue 8 years ago • 10 comments

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference at com.volokh.danylo.visibility_utils.items.ListItemData.getIndex(ListItemData.java:22) at com.volokh.danylo.visibility_utils.items.ListItemData.getVisibilityPercents(ListItemData.java:42) at com.volokh.danylo.visibility_utils.calculator.SingleListViewItemActiveCalculator.calculateActiveItem(SingleListViewItemActiveCalculator.java:309) at com.volokh.danylo.visibility_utils.calculator.SingleListViewItemActiveCalculator.onStateTouchScroll(SingleListViewItemActiveCalculator.java:76)

When I am trying to scroll it is giving the NullPointerException.I didn't find any way to setCurrentItem in SingleListViewItemActiveCalculator

sarathkrrish avatar Apr 02 '16 15:04 sarathkrrish

step 1: inner SingleListViewItemActiveCalculator

if (listItemData.getIndex() != null) { calculateActiveItem(itemsPositionGetter, listItemData); }

step 2: inner ListItemData

public Integer getIndex() {
    return mIndexInAdapter;
}

FutureZhjing avatar Apr 14 '16 10:04 FutureZhjing

inner Class ListItemData

fint to: public int getIndex() { return mIndexInAdapter; }

Changer:

public int getIndex() { return mIndexInAdapter == null ? 1 : mIndexInAdapter ; }

hoanghiephui avatar May 17 '16 14:05 hoanghiephui

Even if I do the above fix, I am stuck with this. Any idea how to resolve this ?

java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.List.get(int)' on a null object reference
                                                                      at com.volokh.danylo.visibility_utils.items.ListItemData.getVisibilityPercents(ListItemData.java:42)
                                                                      at com.volokh.danylo.visibility_utils.calculator.SingleListViewItemActiveCalculator.calculateMostVisibleItem(SingleListViewItemActiveCalculator.java:173)
                                                                      at com.volokh.danylo.visibility_utils.calculator.SingleListViewItemActiveCalculator.onScrollStateIdle(SingleListViewItemActiveCalculator.java:160)
                                                                      at co.talentora.talentoraandroidapp.talentora.fragments.FeedFragment$5.run(FeedFragment.java:423)
                                                                      at android.os.Handler.handleCallback(Handler.java:739)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                      at android.os.Looper.loop(Looper.java:135)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5234)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at java.lang.reflect.Method.invoke(Method.java:372)
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)

pawankumar01 avatar Jun 07 '16 14:06 pawankumar01

Maybe it's the problem related to the onResume() When I scroll, it crashes with this error, but when I press the home button to put the app in the backend and then get back to the app, It appears to work.....

@Override public void onResume() { super.onResume(); if (!feeds.isEmpty()) { recyclerView.post(new Runnable() { @Override public void run() { listItemsVisibilityCalculator.onScrollStateIdle( mItemsPositionGetter, linearLayoutManager.findFirstVisibleItemPosition(), linearLayoutManager.findLastVisibleItemPosition()); } }); } }

RockyLin avatar Jun 08 '16 09:06 RockyLin

What worked for me was putting the code from onResume() in the setOnSCrollListener and OnSroll methods.

ajchili avatar Aug 16 '16 14:08 ajchili

still don't know how to solve this problem!!

jeremyyu123 avatar Nov 23 '16 09:11 jeremyyu123

any updates on this?

aldefy avatar Feb 14 '17 10:02 aldefy

it appears to be all got this error. and no fix so far when using custom adapter

dayanithi06 avatar Apr 02 '17 08:04 dayanithi06

I only get this issue when im loading my data from elsewhere (firebase). If i hardcode all my data in the app then it works. So it seems to be because some values are getting input into the library before your actual data is loaded. Causing the null. If we can find a way to have everything execute only after data is loaded, problem solved. However the library initializes pieces of code in onResume.

dri94 avatar Apr 03 '17 18:04 dri94

You may have async request,putting the code from onResume() in the request callback methods.it works fine.

Example

   @Override
    protected void onResume() {
        super.onResume();
    }
   @Override
    public void onResponse(final List<GuidesBean> response, int id) {
        if (response == null || response.isEmpty()) return;
        if (!response.isEmpty()) {
            mRecyclerView.post(new Runnable() {
                @Override
                public void run() {
                    mVideoVisibilityCalculator.onScrollStateIdle(
                            mItemsPositionGetter,
                            mLayoutManager.findFirstVisibleItemPosition(),
                            mLayoutManager.findLastVisibleItemPosition());
                }
            });
        }
    }

fushenghua avatar Jul 10 '18 02:07 fushenghua