title: Android set Textview from another fragment
body: <p>I want to setText to a Textview from a fragment to another fragment. </p>
  
  <p>How would I do that? Right now I am getting a: <em>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference</em></p>
  
  <p><strong>FragmentRonde1.java</strong></p>
  
  <pre><code>lv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
              ListClickedFragment newFragment = new ListClickedFragment();
              FragmentTransaction transaction = getFragmentManager().beginTransaction();
  
              transaction.replace(R.id.fragment_container, newFragment);
              transaction.addToBackStack(null);
  
              transaction.commit();
  
              Cursor c2 = db.getIdOfSelectedItem(id);
  
              ListClickedFragment fragmentRonde1 = new ListClickedFragment();
  
              if (c2 != null) {
                  c2.moveToFirst();
  
                  // i want to set listClickedTitle from here but listClickedTitle is in ListClickedFragment
                  fragmentRonde1.gettext(c2.getString(c2.getColumnIndex("title")));
  
              }
  
          }
      });
  </code></pre>
  
  <p>Here is the class for the fragment where ListCLickedTitle is : <strong>ListClickedFragment</strong></p>
  
  <pre><code>public class ListClickedFragment extends android.support.v4.app.Fragment {
  
  TextView tvTitle, tvDesc, tv, oop;
  
  
  public ListClickedFragment() {
      // Required empty public constructor
  }
  
  
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      final View rootview2 = inflater.inflate(R.layout.fragment_list_clicked, container, false);
  
      tvTitle = (TextView)getActivity().findViewById(R.id.listClickedTitle);
  
      return rootview2;
  }
  
  public void gettext (String text) {
  
      tvTitle.setText(text);
  
  }
  }
  </code></pre>
  
  <p><strong>LOGCAT</strong></p>
  
  <pre><code>    10-28 09:37:25.373 14349-14349/justin.drawer E/InputEventReceiver: Exception dispatching input event.
  10-28 09:37:25.381 14349-14349/justin.drawer E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at justin.drawer.ListClickedFragment.gettext(ListClickedFragment.java:40)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at justin.drawer.FragmentRonde1$1.onItemClick(FragmentRonde1.java:71)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.widget.AdapterView.performItemClick(AdapterView.java:310)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.widget.AbsListView.performItemClick(AbsListView.java:1145)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.widget.AbsListView$PerformClick.run(AbsListView.java:3042)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.widget.AbsListView.onTouchUp(AbsListView.java:3891)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.widget.AbsListView.onTouchEvent(AbsListView.java:3656)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.View.dispatchTouchEvent(View.java:9294)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2547)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2240)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at com.android.internal.policy.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2403)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1737)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.app.Activity.dispatchTouchEvent(Activity.java:2765)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2364)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.View.dispatchPointerEvent(View.java:9514)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4230)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4096)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3787)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3844)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5922)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5896)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:     at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5857)
  10-28 09:37:25.420 14349-14349/justin.drawer E/MessageQueue-JNI:    at android.view.ViewRootImpl$WindowInputEventReceive
  10-28 09:37:25.420 14349-14349/justin.drawer D/AndroidRuntime: Shutting down VM
  </code></pre>