VideoPlayerManager
VideoPlayerManager copied to clipboard
NullPointerException onScroll
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
step 1: inner SingleListViewItemActiveCalculator
if (listItemData.getIndex() != null) { calculateActiveItem(itemsPositionGetter, listItemData); }
step 2: inner ListItemData
public Integer getIndex() {
return mIndexInAdapter;
}
inner Class ListItemData
fint to: public int getIndex() { return mIndexInAdapter; }
Changer:
public int getIndex() { return mIndexInAdapter == null ? 1 : mIndexInAdapter ; }
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)
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()); } }); } }
What worked for me was putting the code from onResume() in the setOnSCrollListener and OnSroll methods.
still don't know how to solve this problem!!
any updates on this?
it appears to be all got this error. and no fix so far when using custom adapter
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.
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());
}
});
}
}