title: System.console() NullPointerException
body: <p>Here is my code:</p>
  <pre><code>System.out.println(&quot;Enter Username: &quot;);
  String unm=System.console().readLine();
  
  System.out.println(&quot;Enter Password: &quot;);
  char[] pwd=System.console().readPassword();
  
  System.out.println(&quot;Welcome: &quot; + &quot;&quot; + &quot; Your password is &quot; + new String(pwd));
  </code></pre>
  <p>Why am I getting this error?</p>
  <blockquote>
  <p>Enter Username:</p>
  </blockquote>
  <blockquote>
  <p>Exception in thread &quot;main&quot; java.lang.NullPointerException at Cons.main(Cons.java:13)</p>
  </blockquote>