My current structure involves a navDrawer with a list of items in it, pointing to the main fragment which has a RecyclerView containing CardView. When I am setting up the ListView to pass it to registerForContextMenu the app is crashing giving error that initializing object with null value.
The code that i'm using to declare the ListView item to pass is.
ListView LV = (ListView) findViewById(R.id.cv);
where "cv" is the id of the CardView element that holds the data to be displayed.
registerForContextMenu(LV);
At this point the particular error is coming:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnCreateContextMenuListener(android.view.View$OnCreateContextMenuListener)' on a null object reference
the value of LV is coming to be null. I'm new to android, am I missing out something in declaration or while I'm using cast to ListView? Long Click possible in CardView or not?