用户名和密码正确,但“if(username=...)”此 block 不起作用。也没有错误。它向 onPostExecute() 方法返回 0 值。
@Override
public Integer doInBackground(Void... Params){
try{
....
if(userName=="sinan" && password=="123456")
{
returnValue=1;
break;
}
else
{
returnValue=0;
}
}
return returnValue;
}
catch (Exception ex)
{
return (-1);
}
}
阿斯达斯
@Override
protected void onPostExecute(Integer result){
super.onPostExecute(result);
if(result==1)
{
txtViewUserName.setText(userName);
txtViewPassword.setText(password);
}
else if(result.intValue()==0)
{
txtViewUserName.setText("Result 0");
}
....
}
最佳答案
你的错误是你在使用==
操作符,==
操作符比较对象在内存中的位置
使用 equals()
方法代替 ==
运算符比较两个字符串对象
Override
public Integer doInBackground(Void... Params){
try{
....
if(userName.equals("sinan") && password.equals("123456"))
{
returnValue=1;
break;
}
else
{
returnValue=0;
}
}
return returnValue;
}
catch (Exception ex)
{
return (-1);
}
关于android - 在我的 android 应用程序上,即使我从数据库中获得真实值(value),我也无法登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30353412/