title: Null pointer exception for passing data from one fragment to another fragment
body: <p>I am trying to send the data from the alert dialog <strong>EditText</strong> to the another fragment with the help of interface .</p>
  
  <ul>
  <li>I am facing the problem Null Pointer Exception in the fragements and the main activity.</li>
  </ul>
  
  <p><strong>AlertFragment code :</strong></p>
  
  <pre><code>public class AlertDialogFragment extends DialogFragment {
  DialogClick dClick;
  protected AlertDialog adAlert;
  public AlertDialogFragment() {
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  @Override
  public void onAttach(Activity activity){
      super.onAttach(activity);
      dClick = (DialogClick)activity;
  }
  @NonNull
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
      final AlertDialog.Builder adDetails;
      adDetails = new AlertDialog.Builder(getContext());
      LayoutInflater inflater = getActivity().getLayoutInflater();
      adDetails.setTitle("Enter the Details");
      adDetails.setCancelable(true);
      adDetails.setView(inflater.inflate(R.layout.fragment_dialog, null,false));
      adDetails.setPositiveButton(R.string.Ok, new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialogInterface, int i) {
              Dialog view = (Dialog) dialogInterface;
              TextInputEditText Fname = (TextInputEditText) view.findViewById(R.id.edtFname);
              TextInputEditText Lname = (TextInputEditText) view.findViewById(R.id.edtLname);
              String sFname = Fname.getText().toString();
              String sLname = Lname.getText().toString();
              dClick.onDialogPositiveClick(sFname, sLname);
          }
      });
      adDetails.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialogInterface, int i) {
          dismiss();
          }
      });
      adAlert = adDetails.create();
      return adDetails.create();
  }}
  </code></pre>
  
  <p><strong>ListFragment</strong></p>
  
  <pre><code>public class ListViewFragment extends ListFragment {
  View view;
  TextView txt;
  TextView txt2;
  public ListViewFragment() {
  }
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
  
      view = inflater.inflate(R.layout.activity_memo_main, container, false);
      txt = (TextView) view.findViewById(R.id.tvFName);
      txt2 = (TextView) view.findViewById(R.id.tvLName);
      return view;
  }
  public void sendData(String Fname, String Lname){
      txt.setText(Fname);
      txt2.setText(Lname);
  }}
  </code></pre>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>public class MemoMainActivity extends AppCompatActivity implements DialogClick {
  private FragmentManager fragManger ;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_memo_main);
      init();
      setupDefaults();
      setupEvents();
  }
  
  public void init() {
      fragManger = getSupportFragmentManager();
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.menu_main,menu);
      return super.onCreateOptionsMenu(menu);
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      int id = item.getItemId();
      switch (id) {
          case R.id.menuAdd:
              AlertDialogFragment altDialFrag = new AlertDialogFragment();
              altDialFrag.show(fragManger,null);
              break;
      }
      return super.onOptionsItemSelected(item);
  }
  public void setupDefaults(){
  
  }
  public void setupEvents(){
  
  }
  @Override
  public void onDialogPositiveClick(String sFname, String sLname){
      ListViewFragment list = new ListViewFragment();
      list.sendData(sFname,sLname);
  }}
  </code></pre>
  
  <p><strong>Log cat:</strong></p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
                Process: com.Fragemnt.Memo, PID: 27307
                java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
                    at com.Fragemnt.Memo.ListViewFragment.sendData(ListViewFragment.java:27)
                    at com.Fragemnt.Memo.MemoMainActivity.onDialogPositiveClick(MemoMainActivity.java:52)
                    at com.Fragemnt.Memo.AlertDialogFragment$1.onClick(AlertDialogFragment.java:45)
                    at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:157)
                    at android.os.Handler.dispatchMessage(Handler.java:102)
                    at android.os.Looper.loop(Looper.java:135)
                    at android.app.ActivityThread.main(ActivityThread.java:5221)
                    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:899)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  </code></pre>