title: Trying to access a Fragment from another thread to change TextView text
body: <p>I am making an app that is using Fragments and wish to change the text in a TextView based on a message received in a client thread communicating with a laptop. The client server communication is no issue as the client thread is receiving the strings just fine.</p>
  
  <p>I can't seem to properly figure out how to access the fragments TextView and alter its text.
  Here is how I am currently trying to do so:</p>
  
  <pre><code>class ClientThread implements Runnable {
      public void run() {
              mHandler.post(new Runnable() {
                  @Override
                  public void run() {
                      LivingRoomFragment frag = (LivingRoomFragment)getSupportFragmentManager().findFragmentById(R.id.LivingRoomFragment);
                      frag.setText("Inside ClientThread right now");
                  }
              });
      }
  }
  
  
  public static class LivingRoomFragment extends Fragment {
      public static final String ARG_SECTION_NUMBER = "section_number";
      TextView temp;
  
      public LivingRoomFragment(){
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.activity_room_control_fragment1, container, false);
          temp = (TextView) rootView.findViewById(R.id.textView5);
          MainActivity main = new MainActivity();
          new Thread(main.new ClientThread(requests)).start();
          return rootView;
      }   
  
      public void setText(String s){
          temp.setText(s);
      }
  }
  </code></pre>
  
  <p>In this case, MainActivity is the activity extending FragmentActivity.</p>
  
  <p>I'm using an emulator and the app always crashing saying there was a null pointer exception at the line using <code>frag.setText("Inside ClientThread right now")</code>, which I believe means that the instance of LivingRoomFragment is null. It is to my understanding so far that this is supposed to be executed using a Handler because you cannot access the UI from a thread without using a method like this. </p>
  
  <p>What am I doing wrong?</p>