How is the Exception in thread "main" java resolved.lang.NullPointerException?

Good night, I'm doing a task that pretends to work as a Tamagotchi game menu, but when I want to move to case 2 or do an operation again the console tells me java.lang.NullPointerException that I do not know what to refer to. I leave two images of the code I carry so far.

enter the description of the image here

enter the description of the image here

 1
Author: Jorgesys, 2016-06-06

3 answers

If line 79 is this: } while (letra.equals("N") || letra.equals("n"));

Surely letra is coming null.

By the way, in the screenshot you have put letra but in the code you have pasted puts tecla, to see if you are going to be confusing the name of the variables and using a reference that is null.

 1
Author: Jose Serodio, 2016-06-06 08:58:39

You get a null, because in the' menu ' inside the do-while you never ask for letter. How to optimize, I advise you to use string # equalsIgnoreCase (String)instead of checking 2 times with equals if it is the answer in lowercase or uppercase.

Change the do-while and request data by keyboard.

final Scanner in = new Scanner(System.in);
String letra = "N";
do {
    // Creas objeto Pokémon
    // Le estableces valores
    // Muestras datos
    // Preguntas si quiere continuar (S/s o N/n)
    letra = teclado.nextLine();
} while (letra.equalsIgnoreCase('S'));
 0
Author: dddenis, 2016-06-06 11:00:50

The error

Java.lang.NullPointerException

Refers to the existence of a null-valued object variable that you are trying to use.

To avoid this problem you must ensure that your object variable does not have a NULL value, you must initialize it.

The message from line 79 is that the variable linea is not initialized and is null and you try to run the method equals() on it.

while (letra.equals("N") || letra.equals("n"));

I advise you to also use the method equalsIgnoreCase () to simplify your statement, this way you don't have to validate the uppercase and lowercase letter:

   while (letra.equalsIgnoreCase('n'));
 0
Author: Jorgesys, 2016-06-06 14:23:05