Android Change textView text from another method/class
<p>After a click on button1, another layout and another class gets called.
Now I want to change the text of textView out of class 2 which results in an app crash with  java.lang.NullPointerException</p>

<p>important parts of <strong>Class 1</strong></p>

<pre><code>public static TextView A;
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
</code></pre>

<p>[button stuff in class 1]</p>

<pre><code> setContentView(R.layout.raten);
                      final    TextView A = (TextView) findViewById(R.id.A); //the textview I wanna chage
                 max = 10;
                      Easy easy = new Easy(); // the other class
                      easy.e();
</code></pre>

<p>[now the method in class 1 that should change the text]</p>

<pre><code>    public static void Tx(int i)
    {
 A.setText("adsfasdf");
    }
</code></pre>

<p>[important parts of Class 2 ("Easy")]</p>

<pre><code>public void e(){
        System.out.println("called class easy");

    int max = MainActivity.max;
    System.out.println(max);
    for (int i= 0; i&lt;max; i++){
        System.out.println("runde"+i);
 MainActivity.Tx(i);

    }
</code></pre>

<p>I know, some people already asked such questions but I didn't find a working solution. I already understood, that you can't access the UI things outside the UI thread and that the nullpointerexception appears, because he uses the "empty" <code>public static TextView A;</code> and not the <code>final    TextView A = (TextView) findViewById(R.id.A)</code>.</p>

<p>But how I can make it visible for the other methods?</p>

<p>Sorry if the post looks messed up but I didn't konw how to explain my situation in a better way</p>
