-2
I am creating a program that will receive multiple inputs from the user and, when receiving a blank string, should stop receiving entries and continue with the program.
The code runs perfectly through my computer but the college’s automated correction system reports an error:
Exception in thread "main" java.lang.NullPointerException
at SentencaDancante.main(SentencaDancante.java:20)
Line 20 corresponds to while
of the code below:
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String entrada = new String(input.readLine());
int contador = 0;
Frases[] objetos = new Frases[100];
while (entrada.length() != 0){
//the object constructor gets the length and the char[], converted from the "entrada" string.
objetos[contador] = new Frases(entrada.length(), entrada.toCharArray());
// defined method in the Frases class
objetos[contador].converter();
entrada = input.readLine();
contador++;
}
I’ve tried to replace the while
by a while(entrada != null || entrada.length != 0)
. But then Vscode starts reporting nullpointeraccess.
I can take a look at your class Sentences?
– undefined
Possible duplicate of What is Nullpointerexception and what are its main causes?
– nullptr
I had already taken a look at that same post, did not meet what I needed. It was a problem related to the automatic correction system newline
– Diogo Neiss