This question has already been answered:
public class ScrollingActivitySalads extends AppCompatActivity { ... public class RVAdapterSalads extends RecyclerView.Adapter<RVAdapterSalads.CardViewHolder> { public class CardViewHolder extends RecyclerView.ViewHolder { TextView dishName = (TextView) itemView.findViewById(R.id.dish_name); TextView dishConsist = (TextView) itemView.findViewById(R.id.dish_consist); ImageView dishPhoto = (ImageView) itemView.findViewById(R.id.dish_photo); int currentCardPosition; Context mContext; String allDishes = ""; CardView cardView = (CardView) itemView.findViewById(R.id.cv); CardViewHolder(View itemView, Context context) { super(itemView); mContext = context; cardView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(mContext instanceof ScrollingActivitySalads){ ((ScrollingActivityHots)mContext).showSnackbar(currentCardPosition+1); allDishes += "dishName"; allDishes += "/n"; } } }); intent.putExtra("allSalads", allDishes);//error } }.... In the marked place, an error NullPointerException. I noticed that the background of the variables allDishes, if clicked, is red for everyone, and the variable in the marked line is green. Perhaps another variable is perceived inside putExtra? How to fix?