gpt4 book ai didi

java - 空检查不起作用

转载 作者:行者123 更新时间:2023-11-29 07:47:51 25 4
gpt4 key购买 nike

抱歉,如果这是一个低质量的问题,但仍然是一个问题 :) 我在这里使用一个简单的 in the eyes 条件来检查 EditText 的 null Being,

public String theuser=null;
public String thepass=null;

EditText u=(EditText)findViewById(R.id.inputuser);
this.theuser = u.getText().toString();
EditText p =(EditText)findViewById(R.id.inputpassword);
this.thepass = p.getText().toString();

if ((theuser.equals(null))||(thepass.equals(null))){
Toast.makeText(this,"Username and Password Cant Be Empty!",
Toast.LENGTH_SHORT).show();
}else{
Log.i("lifemate","did you click me ?!"+theuser+" "+thepass);
BusProvider.getInstance().post(SendRequestInfo());
}

但 null 检查似乎不起作用!我试过 .equals(null) 和 .equals("") 也还是不行!伙计们知道这是为什么吗?!

最佳答案

null 的比较应该使用 == 运算符来完成。

所以使用if (theuser==null || thepass == null)

关于java - 空检查不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23990174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com