Tutti due i file ha solo tre stringhe
1
2
3
Come mai mi da errore?
public static void main(String[] args) throws IOException {
ArrayList<String> listCliente = new ArrayList<>();
ArrayList<String> listCliente1 = new ArrayList<>();
BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\java\\Desktop\\prova.txt"));
BufferedReader reader1 = new BufferedReader(new FileReader("C:\\Users\\java\\Desktop\\prova1.txt"));
String line = reader.readLine();
while(line!=null) {
System.out.println(line);
line = reader.readLine();
listCliente.add(line);
}
String line1 = reader1.readLine();
while(line1!=null) {
System.out.println(line1);
line1 = reader1.readLine();
listCliente1.add(line1);
}
System.out.println(listCliente);
System.out.println(listCliente1);
for (int i = 0; i < listCliente.size(); i++) {
for (int j = 0; j < listCliente1.size(); j++) {
if (listCliente.get(i).equals(listCliente1.get(j))) {
System.out.println(listCliente.get(i));
}
}
}
}
}
output:
1
2
3
1
2
3
[2, 3, null]
[2, 3, null]
2
3
Exception in thread "main" java.lang.NullPointerException
at it.nexid.Test.main(Test.java:41)