我试图在android中初始化组件,我搜索了互联网并找到了这种类型的声明,但它使我的程序在启动时强制关闭。我究竟做错了什么?
public class MainActivity extends Activity {
private EditText edit =(EditText) findViewById(R.id.editText3); // This code makes my program come up totally empty and crash in few seconds after being blank.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}