Good day! There is such a situation: I use RecyclerView + CardView. It is necessary when you click on the card to open DialogFragment. To do this, in the adapter recyclerview I hung on the CardView listener, in which I call DialogFragment (custom). FragmentManager is required to bring up the dialogue. To do this, I saved the activation link in the adapter and get a manager from it. Below is the code:
public class RVAdapter extends RecyclerView.Adapter<RVAdapter.HeroViewHolder> { List<Hero> heroes; MainActivity activity; @Override public void onBindViewHolder(HeroViewHolder holder, int position) { /*holder.heroName.setText(heroes.get(position).name); holder.heroImage.setImageResource(heroes.get(position).image); holder.heroDescription.setText(heroes.get(position).description); holder.fullDescription.setText(heroes.get(position).fullDescription);*/ не важно holder.cv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SupportBlurDialogFragment dialog = new SupportBlurDialogFragment() { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.dialog_layout, container, false); return v; } }; dialog.show(activity.getSupportFragmentManager(), "log"); } }); } As a result, I get a NullPointerException:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.support.v4.app.FragmentManager ru.spoketplace.vainstatistic.MainActivity.getSupportFragmentManager()' on a null object reference at ru.spoketplace.vainstatistic.fragments.RVAdapter$1.onClick(RVAdapter.java:59) at android.view.View.performClick(View.java:4789) at android.view.View$PerformClick.run(View.java:19881) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5294) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699) What could be the error? Thank you in advance.