2016-08-22 65 views
0

我有一個代碼,應該檢查一個職位是否可用或甚至需要。這裏是我的代碼:代碼沒有正確設置文本

if(!Objects.equals(PhotoEditor, "null")){ 
    if(Objects.equals(PhotoEditor, "N/A")){ 
     tvPhotoEditor.setText("Not Applicable"); 
     cbPhotoEditor.setEnabled(false); 
    }else{ 
     tvPhotoEditor.setText(PhotoEditor + " Scheduled"); 
     cbPhotoEditor.setEnabled(false); 
    } 
} else { 
    tvPhotoEditor.setText("Photo Editor Available"); 
    cbPhotoEditor.setEnabled(true); 
} 

現在,它是從我CRM拉動信息,併爲這個字段設置爲N/A作爲測試,但它返回的結果「N/A計劃」,這意味着它去了else語句,而不是第一個if語句。我如何得到它去if語句代替

+1

那不是你如何檢查空 - 嘗試 - 如果(!Objects.equals(PhotoEditor,null)) – Tasos

+0

'PhotoEditor'的類型是什麼?你可以嘗試'如果(Objects.equals(PhotoEditor.toString(),「N/A」))'? –

+0

Taso,CRM傳遞null對象的文字字符串,這就是爲什麼我這樣做。但是,是的,我知道這是我通常檢查null的方式。 –

回答

0

你只用下面改變你的代碼來解決你的問題

if(!Objects.equals(PhotoEditor, null)){ 

,你也可以使用

if(PhotoEditor != null)){ 

實現