TextView error when setting text

For some reason, my application crashes when I try to install text textview? How can i do this.

private TextView strStatus; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); txtUsername = (EditText) findViewById(R.id.username); strStatus = (TextView) findViewById(R.id.status); //strStatus.setText("test"); // SEEMS TO BE CAUSING THE CRASH setContentView(R.layout.main); } 
 <TextView android:id="@+id/status" android:layout_width="fill_parent" android:layout_height="wrap_content" /> 
+4
source share
1 answer

One small mistake. First you have to do it setContentView

  @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); txtUsername = (EditText) findViewById(R.id.username); strStatus = (TextView) findViewById(R.id.status); strStatus.setText("test"); } 
+11
source

All Articles