我正在尝试制作一个计算器应用程序,但我遇到了一个问题:
(null)
是橙色的,它说:.equals(null) 可能不是预期的。我该怎么办?
case R.id.equal: if(!optr.equals(null)){
if(op2 != 0){
if(optr.equals("+")){
disp.setText(""); /*op1 = op1 + op2;*/
disp.setText("Result : " + Integer.toString(op1));
最佳答案
这就是你的做法。 Null 不是一个对象——所以没有等号:
case R.id.equal: if(optr!=null){
if(op2 != 0){
if(optr.equals("+")){
disp.setText(""); /*op1 = op1 + op2;*/
disp.setText("Result : " + Integer.toString(op1));
关于android - .equals(null) 可能不是预期的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26701675/