【发布时间】:2013-02-18 10:22:23
【问题描述】:
我有这个 if else 语句的代码
@Override
public void onClick(View arg0) {
int aInt = Integer.parseInt(textView1.getText().toString());
if(aInt <= 0) {
Toast.makeText(getApplicationContext(), "Wrong",
Toast.LENGTH_SHORT).show();
} else{
int a=Integer.parseInt(textView1.getText().toString());
int b=a-2;
String s1 = String.valueOf(b);
textView1.setText(s1);
Toast.makeText(getApplicationContext(), "Wrong",
Toast.LENGTH_SHORT).show();
int c =Integer.parseInt(textView5.getText().toString());
int d = c-1;
String s2 = String.valueOf(d);
textView5.setText(s2);
} if(textView5 != null) {
int dInt = Integer.parseInt(textView5.getText().toString());
if(dInt <= 0);
Toast.makeText(getApplicationContext(), "Game Over",
Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.setClass(MainActivity.this, Fifth.class);
startActivity(intent);
SavePreferences("MEM1", textView1.getText().toString());
}
}
};
如果 textView5 的值为 0,我想在这部分代码中启动意图 但即使 textView5 的值还不是 0,它仍然符合新的意图,我不知道我的代码的哪一部分是错误的:
} if(textView5 != null) {
int dInt = Integer.parseInt(textView5.getText().toString());
if(dInt <= 0);
Toast.makeText(getApplicationContext(), "Game Over",
Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.setClass(MainActivity.this, Fifth.class);
startActivity(intent);
}
【问题讨论】:
-
使用
if(dInt <= 0)而不是if(dInt <= 0);
标签: java if-statement syntax