You have to initialize the imageView in onCreate:
public class MainActivity extends Activity {
ImageView imgView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imgView = (ImageView)findViewById(R.id.imageView1);
Button btnV = (Button)findViewById(R.id.btnV);
Button btnInV = (Button)findViewById(R.id.btnInV);
btnV.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
imgView.setVisibility(View.VISIBLE);
}
});
btnInV.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
imgView.setVisibility(View.INVISIBLE);
}
});
}
}