Hello companions,
I've been working on a phone customer billing program for a few days now and I've been able to make considerable progress thanks to the aid of the members on this forum and the Oracle Java reference site. Yesterday, I made some minor changes to my Eclipse layout and basically from there I just started minimizing and maximizing and removing aspects of the interface unknowingly.
Regardless, I have experienced a Null Pointer Exception and I've been doing the best debugging process I've ever done in my life. I still can't locate the resource or tip to help me get back on the right track.
This is the program I am still working on;
First Post (provides concept of program)
This is my updated code;
package spInputOutput; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.BufferedReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; public class spInputOutput { public static PrintWriter outputStream; public static void main(String[] args) throws IOException { readData(); } public static void readData() throws IOException { //Monthly Base Fee of $20 double monthlyBase = 20; double startTime = 0.00; double duration = 0.00; //double amountDue = monthlyBase + (duration * startTime); //ArrayList<Double> amtDue = new ArrayList<Double>(); ArrayList <String> accts = new ArrayList<String>(); //use 'contains' to check whether or not the account number has been accounted for, add or create new instance double daytimeCall = 0.12; /*per minute for calls that started between 8:00 AM and 10:00PM, inclusive $0.05 per minute all other times*/ FileReader fr = new FileReader("input_data.txt"); BufferedReader br = new BufferedReader(fr); String invoice = "invoice.txt"; try { outputStream = new PrintWriter(invoice); } catch (FileNotFoundException e) { e.printStackTrace(); } //String[] a = line.split(":"); for times outputStream.println("Invoice"); outputStream.println("**********"); outputStream.println(""); outputStream.println("Account"); outputStream.println(""); outputStream.println("Amount Due"); //Should eventually use algorithm to calculate the amounts due for each account /* Created to simulate values for Amounts Due for(int i=1; i<4; i++) { double z = ((10+(i*2))+(i*(Math.random()))); outputStream.printf("%.2f", z); outputStream.println("\n"); } */ outputStream.println(""); outputStream.println("**********"); outputStream.println("Total:"); String text = ""; String line = br.readLine(); while(line != null) { text += line; line = br.readLine(); //THE LINE BELOW IS WHERE MY PROGRAM IDENTIFIES THE NULL POINTER EXCEPTION String [] a = line.split(" "); //Account numbers loop for(int i=0; i<1; i++) { //If account number is already in array if() accts.add(a[i]); outputStream.println(a[i]); } } System.out.println(text); System.out.println("Inovice File Incorrectly Created"); System.out.println(accts.get(1)); outputStream.close(); br.close(); } }
This is the message displayed in the console after attempting to run;
Exception in thread "main" java.lang.NullPointerException
at spInputOutput.spInputOutput.readData(spInputOutput .java:79)
at spInputOutput.spInputOutput.main(spInputOutput.jav a:18)
As always, I am grateful for assistance. Any suggestions are welcome, thanks.