Java 意图不与if操作员Android一起工作
当我按下一个按钮将我重定向到一个页面时,它会显示一条消息,但它不起作用。成功后,将显示消息,但不会转发给我Java 意图不与if操作员Android一起工作,java,android,Java,Android,当我按下一个按钮将我重定向到一个页面时,它会显示一条消息,但它不起作用。成功后,将显示消息,但不会转发给我 private void registerUser() { try { Account account = new Account(); account.setpAddress(edt_adress.getText().toString()); account.setpBloodGroup(edt_blood.getSelected
private void registerUser() {
try {
Account account = new Account();
account.setpAddress(edt_adress.getText().toString());
account.setpBloodGroup(edt_blood.getSelectedItem().toString());
account.setpFirstName(edt_first.getText().toString());
account.setpMidName(edt_mid.getText().toString());
account.setpFamilyName(edt_fam.getText().toString());
account.setpGender(edt_gender.getSelectedItem().toString());
account.setpPhone(edt_phone.getText().toString());
account.setpEgn(edt_egn.getText().toString());
account.setuPassword(edt_password.getText().toString());
account.setuUsername(edt_username.getText().toString());
INodeJS accountservice = RetrofitClient.getInstance().create(INodeJS.class);
Call call = accountservice.create(account);
call.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
Account result = (Account) response.body();
Toast.makeText(getApplicationContext(), result.getNotes(), Toast.LENGTH_LONG).show();
if (result.getNotes().equals("Success")) {
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
}
// startActivity(intent);
}
@Override
public void onFailure(Call call, Throwable t) {
Toast.makeText(getApplicationContext(), getString(R.string.createfield), Toast.LENGTH_SHORT).show();
}
});
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
看起来
result.getNotes().equals(“Success”)
不是真的,你认为舒尔应该是这样吗equals
区分大小写,因此“success”不等于“success”,也不等于“success”-请注意空格
也许你可以试试这个说法:
result.getNotes().toLowerCase(Locale.getDefault()).trim().equals("success")
toLowerCase
将使您的所有字母大写,而trim
将删除字符串结尾处的所有空格
还有equalsIgnoreCase
方法,因此它也可能如下所示:
result.getNotes().trim().equalsIgnoreCase("success")
那么,if(result.getNotes().equals(“Success”){
这是真的吗?你的祝酒词在onResponse
里面,而不是如果
文本拼写正确。他尝试了你的例子,但仍然不起作用