title: changing the setText value in a fragment from main activity
body: <p>I've been trying to change my textViews text in a fragmentActivity based on whether or not user has clicked the button in the first main activity. I have 2 xml files and 2 .java files and the code at the moment crashes when the app starts.
  This is the button code</p>
  
  <pre><code>public void getNum(View view) {
  
          buttonCheck = 1;
          }
  </code></pre>
  
  <p>And this is the code from FragmentTab</p>
  
  <pre><code>public class FragmentTab extends Fragment {
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View v = inflater.inflate(R.layout.fragment_layout, container, false);
  
      TextView tv = (TextView) v.findViewById(R.id.text);
      tv.setText("nothing has been input yet");
  
      if (FirstActivity.buttonCheck == 1){
      tv = (TextView) v.findViewById(R.id.text);
      tv.setText("value");}
  
  
      FirstActivity.buttonCheck = 0;
      return v;
  }
  </code></pre>
  
  <p>The first error i get from my code from logcat is: "java.lang.NullPointerException
              at com.ezentertainment.dietabialkowa.FragmentTab.onCreateView(FragmentTab.java:23)" and line 23 is  <code>tv.setText("nothing has been input yet");</code>
  any help at all is greatly appreciated, I have been fighting with this issue for quite some time now..</p>
  
  <p>tl;dr how to change fragment value based upon input from mainActivity?</p>
  
  <p><strong>edit:</strong> here is the fragment_layout.xml</p>
  
  <pre><code>&lt;LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  
  android:orientation="vertical"
  android:background="#eaecee"&gt;
  
  &lt;TextView
      android:id="@+id/textResult"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
  
      android:text="value"
      android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  </code></pre>
  
  <p></p>