There is a java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.widget.LinearLayout.findViewById(int)' on a null object reference
I understand that I refer to the zero object, but I can not figure out how to fix it. I tried everything I knew.
In recyclerAdapter I try to set an invisible object to VISIBLE status by clicking
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ItemViewHolder> implements ItemTouchHelperAdapter { private List<File> mItems; Context mContext; RelativeLayout relativeLayout private final OnStartDragListener mDragStartListener; public RecyclerAdapter(List<File> mImgGson, Context context, OnStartDragListener dragStartListener) { mDragStartListener = dragStartListener; mItems = mImgGson; mContext = context; } @Override public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false); ItemViewHolder itemViewHolder = new ItemViewHolder(view); relativeLayout = (RelativeLayout)view.findViewById(R.id.layoutFirst); return itemViewHolder; } @Override public void onBindViewHolder(final ItemViewHolder holder, int position) { Picasso.with(mContext).load(mItems.get(position)).fit().centerCrop().error(R.mipmap.ic_launcher).into(holder.handleView); holder.handleView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { View trash = relativeLayout.findViewById(R.id.trash_can); trash.setVisibility(View.VISIBLE); } }); } Markup:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center" android:id="@+id/layoutFirst" tools:context=".MainActivity" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center"> <ImageView android:id="@+id/trash_can" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:padding="40dip" android:visibility="gone" > </ImageView> <android.support.v7.widget.RecyclerView android:id="@+id/my_recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:scaleType="center"/> </LinearLayout> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button" android:layout_gravity="center_horizontal" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:onClick="onClick" />