I was just testing input/output, there was no special purpose, this is the last code that had run successfully:
public class MainActivity extends AppCompatA
Before setting setContentView() you are not able to initialize the view items.Because view will not be exists for activity at that time.
Keep the initializations in one separate method and call that method after setting the view to the activity.