You have to place the btn and tv initialization after the setContentView inside the onCreate
also to add final to the tv as you are using it in an inner class
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.button1);
final TextView tv = (TextView)findViewById(R.id.textView1);
The End.