Logcat error ( it was not able to handle null exception in glide when no image is found). I wasn't able to put if/else statement.
2020-11-19 10:46:27.887 9386-9386/com.example.bookretrofit E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.bookretrofit, PID: 9386
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.example.bookretrofit.Imagelink.getSmallThumbnail()' on a null object reference
at com.example.bookretrofit.RecyclerViewAdapter.onBindViewHolder(RecyclerViewAdapter.java:56)
at com.example.bookretrofit.RecyclerViewAdapter.onBindViewHolder(RecyclerViewAdapter.java:19)
at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:7065)
at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7107)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:6012)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6279)
at androidx.recyclerview.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:288)
at androidx.recyclerview.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:345)
at androidx.recyclerview.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:361)
at androidx.recyclerview.widget.GapWorker.prefetch(GapWorker.java:368)
at androidx.recyclerview.widget.GapWorker.run(GapWorker.java:399)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7548)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
RecyclerViewAdapter
public void onBindViewHolder(@NonNull MyViewHolder holder, int i) {
VolumeInfo volumeInfo = this.volumeInfo.get(i).getVolumeInfo();
holder.tvTitle.setText(volumeInfo.getTitle());
if (volumeInfo.getAuthors() != null && !volumeInfo.getAuthors().isEmpty()) {
holder.tvAuthor.setText(volumeInfo.getAuthors().get(0));
} else {
holder.tvAuthor.setText("NO AUTHOR");
}
Glide.with(mContext).load(volumeInfo.getImageLinks().getSmallThumbnail()).into(holder.ivThumbnail);
I want to return a default image from Drawable if the image load is null. How can I do it with if/else statement. This part of the code is creating all the problem
Glide.with(mContext).load(volumeInfo.getImageLinks().getSmallThumbnail()).into(holder.ivThumbnail);
Aucun commentaire:
Enregistrer un commentaire