Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just on its own, the problem is that you've given an expression which isn't a statement.</p> <p>With an assignment, however, it's fine:</p> <pre><code>import java.util.*; public class Test { public static void main(String[] args) { HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); String x = map.containsKey("A") ? "" : ""; } } </code></pre> <p>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.</p> <p>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:</p> <pre><code>getResponseDataMap().containsKey("A") ? a.setText(getResponseDataMap().get("A").toString()):"" </code></pre> <p>I <em>suspect</em> you want:</p> <pre><code>a.setText(getResponseDataMap().containsKey("A") ? getResponseDataMap().get("A").toString() : null); </code></pre> <p>However, I would personally write this as:</p> <pre><code>Object response = getResponseDataMap().get("A"); a.setText(response == null ? "" : response.toString()); </code></pre> <p>On the other hand, if you <em>only</em> want to set the text when the map contains the key, then you should go back to your original <code>if</code> statement, or possibly:</p> <pre><code>Object response = getResponseDataMap().get("A"); if (response != null) { a.setText(response.toString()); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload