I'm using the Retrofit to test and learn it as I have a project on it. While I use https://jsonplaceholder.typicode.com/photos for binding the photo into the recycle view. The issue is I can't scroll above 9 images; I mean whenever I scroll down to the 10th image, it is shown and then the app crashes. img
2020-03-21 15:11:48.286 9426-9426/navneet.com.carsrecyclerview E/AndroidRuntime: FATAL EXCEPTION: main
Process: navneet.com.carsrecyclerview, PID: 9426
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:714)
at com.pkmmte.view.CircularImageView.refreshBitmapShader(CircularImageView.java:341)
at com.pkmmte.view.CircularImageView.invalidate(CircularImageView.java:262)
at android.widget.ImageView.setImageDrawable(ImageView.java:572)
at com.squareup.picasso.PicassoDrawable.setPlaceholder(PicassoDrawable.java:59)
at com.squareup.picasso.RequestCreator.into(RequestCreator.java:728)
at navneet.com.carsrecyclerview.CarsAdapter.onBindViewHolder(CarsAdapter.java:58)
at navneet.com.carsrecyclerview.CarsAdapter.onBindViewHolder(CarsAdapter.java:24)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6781)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6823)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6019)
at android.support.v7.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:286)
at android.support.v7.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:343)
at android.support.v7.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:359)
at android.support.v7.widget.GapWorker.prefetch(GapWorker.java:366)
at android.support.v7.widget.GapWorker.run(GapWorker.java:397)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
the issue is similar to Android Picasso image loading app crash when scrolling RecyclerView but my point looks different.
Picasso.get().load(carsModels.get(i).getUrl()).noFade().resize(150,150).into(viewHolder.car_image, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError(Exception e) {
Toast.makeText(context, "An error occurred", Toast.LENGTH_SHORT).show();
}
});
any help will be appriciated. thank you.
It seems to me that the problem may not be with Picasso. It could be with the third party CircularImageView
that you are using. You can put a debug breakpoint at the android.graphics.Bitmap.createScaledBitmap(Bitmap.java:714)
and see why the Bitmap
object is null there. Then, you can go down the stack trace and figure out why it is null. That will give you a better idea of what you need to do to make sure your Bitmap
object is instantiated before hitting that piece of code.
If you do find something, please update here so that I can edit this answer after better understanding the reason for your NullPointerException.