title: Set text on TextView on button click from another class on android
body: <p>​Hi everyone,</p>
  
  <p>If anyone can explain me why the following code not working would be great!
  So, I want to set text on a TextView on button click by calling a method from another class. All this just try to keep methods belong together in same java file for example all methods regarding animations in Animations.java. But I cannot figuring out how to do it and always got NullPointerException​ fault.</p>
  
  <p>Here is the <strong>main class</strong> </p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  
  
  public SeconClass secondClass = new SeconClass();
  TextView myview;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      myview =  (TextView) findViewById(R.id.textView);
      myview.setText("First class");
  
  
     final Button button = (Button) findViewById(R.id.button2);
      button.setOnClickListener(new View.OnClickListener() {
  
          public void onClick(View v) {
              secondClass.ChangeText();
  
          }
      });
  }
  
   }
  </code></pre>
  
  <p>and the <strong>second one</strong></p>
  
  <pre><code>public class SeconClass extends AppCompatActivity {
  
   TextView myview;
  
  public void ChangeText(){
  
      myview = (TextView)findViewById(R.id.textView);
      myview.setText("From second Class");
  }
  
  }
  </code></pre>