I want to perform pagination and have implemented it . It runs but the exact paages keep repeating themselves.
public class ScheduleDataSource extends PageKeyedDataSource<Long,GeneralMatchItem> {
public void loadInitial (@NonNull LoadInitialParams<Long> params, @NonNull LoadInitialCallback<Long, GeneralMatchItem> callback){
total_items = response_obj.getInt("total_items");
....
....
callback.onResult(internationalScheduledMatchItemsList,null, 2L);
}
public void loadAfter(@NonNull LoadParams<Long> params, @NonNull LoadCallback<Long, GeneralMatchItem> callback) {
....
long nextKey = (params.key == total_items)? null : params.key+1;
callback.onResult(tempList,nextKey);
}
...
}
What I have tried:
I tried to track the position manually like this mentioned in the code block above:
As i keep srolling then the key gets added till it reaches 12,i.e, 12/12 complete and suddenly i get a null pointer exception
D/ScheduleDataSource: KEY 11AND TOTAL ITEMS :12
I was learning
from this tutorial and had implemented most of it. But i can't get rid of this error .
The null pointer i get is :
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xyz, PID: 5794
java.lang.NullPointerException: Attempt to invoke virtual method 'long java.lang.Long.longValue()' on a null object reference
at com.xyz.homescreen_new.utilities.schecdule_util.ScheduleDataSource$2.onResponse(ScheduleDataSource.java:252)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:71)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
I am not able to understand what is going wrong in this. Please help .
TIA . :)