Here is the code:
File tempFile = new File("myTempFile.txt");
tempFile.createNewFile();
File inputFile = new File("Friend_list.txt");
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
String currentLine;
while((currentLine = reader.readLine()) != null)
{
String trimmedLine;
trimmedLine = currentLine.trim();
}
In this part of the code, there is a NullPointerException
. The exact exception is mentioned below:
Exception in thread "main" java.lang.NullPointerException: Cannot invoke
"String.trim()" because "currentLine" is null at com.company.Main.delete(Main.java:167)
at com.company.Main.main(Main.java:48)
The question is if the string is null then how could it enter the while loop? I cross checked the file, data is there in the file then how could it be null?