gpt4 book ai didi

java - 为什么这段代码会进入我的方法的错误 block ?

转载 作者:行者123 更新时间:2023-12-02 07:19:44 26 4
gpt4 key购买 nike

我有一个查询,我正在从同一类中的另一段代码调用这样的方法

String message = "null";
//In this case have too show the Yes/No button screen
return performManualVerification(transaction, patientId, scriptInfo, message);

如上所示,消息包含字符串 null,我将其传递给下面的方法,但在调试时,我检查它是否没有进入空检查 block ,它应该进入空检查 block ,它正在进行无电话 block 。请指教

private int performManualVerification(ITransaction transaction,
String patientId, String scriptInfo, String message)
{

if (message.equalsIgnoreCase(null))
{
int UserResponse = messageBox.showMessage("patientinfoVerification",
null, IMessageBox.YESNO);

if (UserResponse == IMessageBox.YES) {
Map<String, List<String>> ppvValidatedinfo = getValidatedPatientData(transaction, patientId, scriptInfo);
if(ppvValidatedinfo.get(patientId) != null){

return MANUALLY_VERIFIED; // manually verified
}

}
return RETURN_SALE;
}


messageBox.showMessage("Nophone", null, IMessageBox.OK);

int UserResponse = messageBox.showMessage("patientinfoVerification",
null, IMessageBox.YESNO);

if (UserResponse == IMessageBox.YES) {

Map<String, List<String>> ppvValidatedinfo = getValidatedPatientData(transaction, patientId, scriptInfo);
if(ppvValidatedinfo.get(patientId) != null){

return MANUALLY_VERIFIED; // manually verified
}

}
return RETURN_SALE;
}

最佳答案

String message = "null";

这是一个值为 null 的字符串。但你需要的是,

String message = null;

了解What is null in Java? @polygenelubricants 的帖子和答案得到了很好的解释。

还要看看这个约束,如果消息为空,这会给你一个 NullPointerException

 if (message.equalsIgnoreCase(null)) 

所以首先检查它是否为空。

if(message == null) {
// do something.
} else {
// Do something.
}

关于java - 为什么这段代码会进入我的方法的错误 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14412555/

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