I am making online news using public API and using Picasso to load data from system. my application is running smoothly. however, the application sometimes crash with the error showing that
at com.squareup.picasso.Picasso.load(Picasso.java:332) at com.tonyapp.hoanguhsk.CustomAdapter.onBindViewHolder(CustomAdapter.java:49) at com.tonyapp.hoanguhsk.CustomAdapter.onBindViewHolder(CustomAdapter.java:20) at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:7254) at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7337) at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:6194) at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6460) 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:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I Check at my customAdapter.java file and try to fix the error at Java:49. I try to test and use many solutions which I searched from other people having same issue with my case. Unfortunately, the error still displays. below lines is my CustomAdapter.java code:
holder.text_title.setText(headlines.get(position).getTitle()); holder.text_source.setText(headlines.get(position).getAuthor()); holder.txt_date.setText(headlines.get(position).getPublishedAt()); if (headlines.get(position).getUrlToImage()!=null){ Picasso.get().load(headlines.get(position).getUrlToImage()).into(holder.img_headline); } holder.cardView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { listener.OnNewsClicked(headlines.get(position)); Intent intent = new Intent(context,Webview.class); intent.putExtra("url",headlines.get(position).getUrl()); context.startActivity(intent);
Can anyone please help me how to fix this crash? thanks a lot for your support.