由于某些原因,当我尝试设置textview的文本时,我的应用程序崩溃了?我怎么能过来这个。
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"
/>
答案 0 :(得分:11)
一个小错误,你应该先做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");
}