好了,我尝试使用DDMS调试我的代码,但还不能解决问题。我认为这是因为我的程序在启动时崩溃了。无论如何,我向一个伙伴展示了此内容,但他不知道我在做什么错。有人可以指出为什么我的应用在启动时崩溃吗?
谢谢:
http://pastebin.com/ZXxHPzng
最佳答案
您遇到的问题是要在全局区域中创建UI元素。如果希望它成为全局对象,则可以在此处声明它们,但是只有在设置了内容 View 之后才能实例化它们。例如:
private RadioButton rockRB;
private RadioButton paperRB;
private RadioButton scissorsRB;
private TextView result;
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Content View Must be set before making UI Elements
rockRB = (RadioButton)findViewById(R.id.radioRock);
paperRB = (RadioButton)findViewById(R.id.radioPaper);
scissorsRB = (RadioButton)findViewById(R.id.radioScissors);
result = (TextView)findViewById(R.id.result);
关于android - 新应用在启动时崩溃,调试无济于事,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7640026/