NullPointerException in FileInputStream text file
package Cheska;
import java.io.*;
public class LongExam {
@SuppressWarnings("deprecation")
public static void main(String[] args) throws IOException {
String thisLine = "", thisLine1 = "", firstParse = "", secondParse = "";
int total = 0, total1 = 0, totalAmt = 0;
FileOutputStream fos = new FileOutputStream ("src/Cheska/totals.txt");
PrintStream myOutput = new PrintStream(fos);
FileInputStream fis = new FileInputStream("src/Cheska/products.txt");
DataInputStream myInput = new DataInputStream(fis);
FileInputStream fis1 = new FileInputStream("src/Cheska/price.txt");
DataInputStream myInput1 = new DataInputStream(fis1);
thisLine = myInput.readLine();
thisLine1 = myInput1.readLine();
System.out.println(thisLine1.substring(19,21));
myOutput.println("Welcome to INPROLA Grocery!");
myOutput.println(" ");
myOutput.println(" ");
myOutput.println(" Item Qty");
while (thisLine != null)
{
firstParse = thisLine.substring(19,21);
total = total + Integer.parseInt(firstParse);
secondParse = thisLine1.substring(19,21);
total1 = Integer.parseInt(secondParse);
totalAmt = total1 * total;
myOutput.println(thisLine + " " + totalAmt);
thisLine=myInput.readLine();
thisLine1 = myInput.readLine();
}
{
myOutput.println("----------------------------");
myOutput.println("The total: " + total + " " + totalAmt);
myOutput.println(" ");
myOutput.println(" ");
myOutput.println("Thank You for Shopping! ^_^ Have a nice day!");
}
}
}
Hi, I'm a first year IT student. I'm new to java. I can't seem to get the error from this while loop.
while (thisLine != null)
{
firstParse = thisLine.substring(19,21);
total = total + Integer.parseInt(firstParse);
secondParse = thisLine1.substring(19,21);
total1 = Integer.parseInt(secondParse);
totalAmt = total1 * total;
myOutput.println(thisLine + " " + totalAmt);
thisLine=myInput.readLine();
thisLine1 = myInput.readLine();
}
The bold line is said to be null, but I've double-checked the codes, I can't seem to see anything wrong with it. Help?