0
I want to input in java from console, but it is throwing NullPointerException
import java.io.Console; public class ConsoleReadString { public static void main(String[] args) { Console c = System.console(); String s = c.readLine(); System.out.println("You entered string " + s); } } //this throws a nullPointerException //also, I am writing this in eclipse and not codeplayground
4 Respuestas
0
I figured it out, it only runs on console, and not on an ide.
+ 1
depends if there is console or not, I ran it on android tablet (by jStudio) and it works.
If you don't like Scanner use BufferedReader
public static void main(String[] args) throws IOException {
//Console c = System.console();
BufferedReader c = new BufferedReader(
new InputStreamReader(System.in));