In the code snippet below, you are supposed to compare the value of items in array linhas
with String
entered by user p
. It's working, but it always gives the error:
Stack trace - Exception in thread "main" java.lang.NullPointerException at MainSwitch.main (MainSwitch.java:229)
The code:
String guardar;
String lista[] = new String [tamMax];
System.out.println("Insira a palavra que pretende pesquisar:");
p = reader.next();
for(int i = 0; i < linhas.length; i++)
{
guardar = linhas[i];
lista = guardar.split(" "); //linha do erro
for(int k = 0; k < lista.length; k++)
{
if(lista[k].equals(p))
{
System.out.println("Linha " + i + ": " + linhas[i]);
}
}
}