当我从这里开始时,我的 android 应用程序崩溃是我在不同设备上尝试过的代码,它编译得很好
public class MyActivity extends Activity {
int userAns;
int ran1;
int ran2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ran1 =(int)(Math.random()*50+1);
ran2 =(int)(Math.random()*50+1);
TextView number1 = (TextView) findViewById(R.id.textView);
number1.setText(ran1);
TextView number2 = (TextView) findViewById(R.id.textView3);
number2.setText(ran2);
ans =ran1+ran2;
}
public void sendMessage(View view){
String userAnsS = ((EditText)findViewById(R.id.editText)).getText().toString();
userAns= Integer.parseInt(userAnsS);
if (userAns == ran1 + ran2) {
return;
}