0

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

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

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

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;   
  }
4

3 回答 3

2

String message = "null";

This is a string with value as null. But what you need is,

String message = null;

Read about What is null in Java? post and the answer written by @polygenelubricants was well explained.

And also look at this constraint, this will give you a NullPointerException if message is null.

 if (message.equalsIgnoreCase(null)) 

So first check whether it is null or not.

if(message == null) {
   // do something.
} else {
   // Do something.
}
于 2013-01-19T08:39:35.967 回答
0

我认为您应该在引号中使用 null 来获得预期的结果。

于 2013-01-19T16:56:31.063 回答
0

要解决此问题,您应该使用带引号的“null”,而不仅仅是null,它具有不同的含义。

  • "null" 只是另一个 Java `String。
  • null(不带引号)是可以分配给对象引用的文字,通常意味着它们不引用任何对象。

另一方面,如果你只想为引用分配一个空值,你应该使用空文字而不是String你可以像这样比较它:

    String s = null;
    if(s == null)
于 2013-01-19T08:33:43.350 回答