I have been reading the possible solutions to this error, but I don't quite understand it, here is the code and the output it gives me:
import java.io.Console;
public class Ejercicio3 {
public static void main(String[] args) {
Console c = System.console();
System.out.println("¿Cuántas puertas quieres que tenga el coche?");
String numPuertas = c.readLine(); /* Here is the error */
int numNum = Integer.parseInt(numPuertas);
if (numNum == 3) {
System.out.println("Es un coche deportivo");
}
else if (numNum == 5) {
System.out.println("Es un coche familiar");
}
else {
System.out.println("¿Seguro que el coche tiene " + numNum + " puertas?");
}
}
}
Output
¿Cuántas puertas quieres que tenga el coche?
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.io.Console.readLine()" because "<local1>" is null
at Ejercicio3.main(Ejercicio3.java:13)
But it won't let me answer the question