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.
can you please help?
println("What is your name ");
def fName = System.console().readLine()
println("Hello" + fName)
Error in Groovy console
groovy> print("What is your name ")
groovy> def fName = System.console().readLine()
groovy> println("Hello" + fName)
What is your name
Exception thrown
java.lang.NullPointerException: Cannot invoke method readLine() on null object
at ConsoleScript54.run(ConsoleScript54:2)
Error in Eclipse
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)