以下程序强制退出并崩溃,我不明白为什么,
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
TextView tv = (TextView) findViewById(R.id.text);
Button btn1 = (Button) findViewById(R.id.button1);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void clicked(View v) {
tv.setText(btn1.getText());
}
}
但移动后
TextView tv = (TextView) findViewById(R.id.text);
Button btn1 = (Button) findViewById(R.id.button1);
在 clicked 函数内部它可以工作,这是为什么呢?
谢谢你的帮助..