Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have a recyclerView. When I click on a item in the Recyclerview, I want to add a picture to the imageview in my activity. I try using Glide and it doesn't. I get this error: Argument must not be null. I think the problem is: imageView is not in Recyclerview. That's why I can't access Imageview from my Adapter class. How do I fix this?
Adapter Class
NOTE: imageView is not in Recyclerview.
public ViewHolder(@NonNull View itemView) {
super(itemView);
image= itemView.findViewById(R.id.imageView);
imageViews = itemView.findViewById(R.id.cards);
imageViews.setOnClickListener(this);
@Override
public void onClick(View v) {
if(v == imageViews){
Glide.with((MainActivity)context).load(R.drawable.picture).fitCenter().into(image);
main activity XML
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/RecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY">
</androidx.recyclerview.widget.RecyclerView>
<ImageView
android:id="@+id/imageView"
android:layout_width="80dp"
android:layout_height="125dp"
app:srcCompat="@drawable/examplePicture" />
LOGCAT
java.lang.NullPointerException: Argument must not be null
at com.bumptech.glide.util.Preconditions.checkNotNull(Preconditions.java:31)
at com.bumptech.glide.util.Preconditions.checkNotNull(Preconditions.java:25)
at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:685)
at com.example.android.TarotModule.CustomAdapter$ViewHolder.onClick(CustomAdapter.java:82)
at android.view.View.performClick(View.java:5156)
at android.view.View$PerformClick.run(View.java:20755)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.