title: Error while trying to get input in groovy
body: <p>I am very new to groovy, I am using the below piece of code in Groovy console and Eclipse (running it as Groovy script), however getting the below error.</p>
  
  <p>can you please help?</p>
  
  <pre><code>println("What is your name ");
  def fName = System.console().readLine()
  println("Hello" + fName)
  </code></pre>
  
  <h1>Error in Groovy console</h1>
  
  <pre><code>groovy&gt; print("What is your name ") 
  groovy&gt; def fName = System.console().readLine() 
  groovy&gt; println("Hello" + fName) 
  </code></pre>
  
  <p>What is your name<br>
  Exception thrown</p>
  
  <p>java.lang.NullPointerException: Cannot invoke method readLine() on null object</p>
  
  <pre><code>at ConsoleScript54.run(ConsoleScript54:2)
  </code></pre>
  
  <h1>Error in Eclipse</h1>
  
  <p>What is your name 
  Caught: java.lang.NullPointerException: Cannot invoke method readLine() on null object
  java.lang.NullPointerException: Cannot invoke method readLine() on null object
      at sample.run(sample.groovy:2)</p>