title: Android Fragment TextView setText from activity
body: <p>I'm having a problem: I have TabLayout with two tabs. One Tab contains a TextView.
  I want to change the text of the TextView from MainActivity (later from a Thread in MainActivity). But it throws an NPE and I don't know how to solve it.</p>
  
  <p>Here is my MainActivity.java-code:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  private SectionsPagerAdapter mSectionsPagerAdapter;
  private ViewPager mViewPager;
  
  public static ThreadConnected myThreadConnected;
  TabTerminal tabT;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
  
      mViewPager = (ViewPager) findViewById(R.id.container);
      mViewPager.setAdapter(mSectionsPagerAdapter);
  
      TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
      tabLayout.setupWithViewPager(mViewPager);
  
      tabT = new TabTerminal();
      tabT.setText("324");
  }
  
  public class SectionsPagerAdapter extends FragmentPagerAdapter {
  
      public SectionsPagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int position) {
          //Returning the current tabs
          switch (position) {
              case 0:
                  TabControl tab1 = new TabControl();
                  return tab1;
              case 1:
                  TabTerminal tab2 = new TabTerminal();
                  return tab2;
              default:
                  return null;
          }
      }
  
      @Override
      public int getCount() {
          return 2;
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          // ...
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And here is the Fragment with TextView:</p>
  
  <pre><code>public class TabTerminal extends Fragment {
  
  static TextView txtterminalout;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.tab_terminal, container, false);
      TextView txtterminalout = (TextView) rootView.findViewById(R.id.terminalout);
  
      return rootView;
  }
  
  public void setText(String text) {
      TextView t = (TextView) getView().findViewById(R.id.terminalout);
      t.setText(text);
  }
  </code></pre>
  
  <p>}</p>