Change TextView text

remove this.. setContentView(tv1);


Your approach is incorrect. I think it will be Null Pointer Exception (next time post log cat)

You need to specify the layout you are using first, before finding views.

Java:

// Specify the layout you are using.
setContentView(R.layout.yourlayout);

// Load and use views afterwards
TextView tv1 = (TextView)findViewById(R.id.textView1);
tv1.setText("Hello");

Kotlin:

// Specify the layout you are using.
setContentView(R.layout.yourlayout)

// Load and use views afterwards
val tv1: TextView = findViewById(R.id.textView1)
tv1.text = "Hello"

Click Here to study exactly you want to know


I got the same problem. My app was stopping too. Actually, I was writing the code outside of the function/method. So to fix this problem, these lines

TextView tv1 = (TextView)findViewById(R.id.textView1);
tv1.setText("Hello");

must be inside a function/method. (can be user defined) (I am new to android studio so I don't know the reason behind the problem but I only know how to fix this. Maybe this helps new ones despite this question being 8 years old.)