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
important parts of Class 1
public static TextView A;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
[button stuff in class 1]
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();
[now the method in class 1 that should change the text]
public static void Tx(int i)
{
A.setText("adsfasdf");
}
[important parts of Class 2 ("Easy")]
public void e(){
System.out.println("called class easy");
int max = MainActivity.max;
System.out.println(max);
for (int i= 0; i<max; i++){
System.out.println("runde"+i);
MainActivity.Tx(i);
}
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" public static TextView A; and not the final TextView A = (TextView) findViewById(R.id.A).
But how I can make it visible for the other methods?
Sorry if the post looks messed up but I didn't konw how to explain my situation in a better way