What is wrong in this codeif(getResponseDataMap().containsKey("A"){
a.setText(getResponseDataMap().get("A").toString);
}
Converted like this .
getResponseDataMap().containsKey("A")?a.setText(getResponseDataMap().get("A").toString()):""
where getLocalRequestDataMap is a HashMap . And setText is function of android
It give compile time error
Multiple markers at this line
– Type mismatch: cannot convert from String to
boolean
– Syntax error, insert “)” to complete Expression
– Syntax error on token “)”, delete this token
Just on its own, the problem is that you’ve given an expression which isn’t a statement.
With an assignment, however, it’s fine:
I suspect the problem is in some code you haven’t shown. Please give more context – ideally a short but complete program like mine, but which demonstrates the error.
EDIT: Now that you’ve edited the question, you’ll probably get a different error. The conditional operator isn’t a valid stand-alone statement, and each of the operands needs to be a non-void expression (with some other caveats as well). So instead of this:
I suspect you want:
However, I would personally write this as:
On the other hand, if you only want to set the text when the map contains the key, then you should go back to your original
ifstatement, or possibly: