I use this code:
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater
In the following code I feel context is null hence you get the error change the following code:
public void onClick(View v) {
Intent myIntent = new Intent(context, MainActivity2Activity.class);
context.startActivity(myIntent);
}
change the above code to:
public void onClick(View v) {
Intent myIntent = new Intent(getApplicationContext(), MainActivity2Activity.class);
context.startActivity(myIntent);
}
or
public void onClick(View v) {
Intent myIntent = new Intent(getBaseContext, MainActivity2Activity.class);
context.startActivity(myIntent);
}
I feel what you are doing is not correct to use onClicks you need to set an interface as shown below:
@Override
public void onClick(View view) {
if (clickListener != null) {
clickListener.itemClicked(view, getPosition());
}
}
public interface ClickListener {
public void itemClicked(View view, int position);
}
Now you need to implement the interface in your activity that will work fine. Try this.
Hope this helps.