You need to get your UI elements after inflating your layout, otherwise findViewById
returns null
and hence the NPE is thrown when you try to set the text on your textView
.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); /// I swap these two lines
final TextView tv = (TextView)findViewById(R.id.textView1); ///
ImageView img = (ImageView) findViewById(R.id.imageView1);