For some reason my application crashes when I try to set the text of a textview? How can I over come 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"
/>
One small mistake , You should do that setContentView first
@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");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With