Note that there are some explanatory texts on larger screens.

plurals
  1. POException in thread "main" java.lang.NullPointerException cann't write to a class
    primarykey
    data
    text
    <p><strong>So I have this code :</strong></p> <pre><code>package Firstpack; import java.io.*; import java.util.*; public class Main { public static void menu() { System.out.println("Welcome"); System.out.println("1. Add a record "); System.out.println("2. See all records "); System.out.println("3. See a category"); System.out.println("4. Total spend(Year)"); System.out.println("5. Spend in a month"); System.out.println("6. Chose by index"); System.out.println("7. Exit "); System.out.print("&gt;"); Scanner in = new Scanner(System.in); int enteredInt = in.nextInt(); in.close(); switch (enteredInt) { case 1: recording(); break; case 2: System.out.print(" You have chosen -&gt; See all records"); break; case 3: System.out.print(" You have chosen -&gt; See a category"); break; case 4: System.out.print(" You have chosen -&gt; Total spend(Year)"); break; case 5: System.out.print(" You have chosen -&gt; Spend in a month"); break; case 6: System.out.print(" You have chosen -&gt; Chose by index"); break; case 7: System.out.print(" Bye! "); break; default: menu(); } } public static void recording() { System.out.println(" You have chosen -&gt; Add a record"); record rec = new record(); Scanner in = new Scanner(System.in); System.out.print("Enter Amount &gt; "); rec.amount = in.nextDouble(); System.out.print("Enter Category &gt; "); rec.category = in.next(); System.out.print("Enter Details &gt; "); rec.details = in.next(); try { FileWriter fw = new FileWriter("findme.txt"); BufferedWriter bw = new BufferedWriter(fw); bw.write(String.valueOf(rec.amount)); bw.write(rec.category); bw.write(rec.details); bw.close(); fw.close(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { menu(); } } </code></pre> <p>And it throws me this:</p> <pre><code>Exception in thread "main" java.lang.NullPointerException at java.io.Writer.write(Unknown Source) at Firstpack.Main.recording(Main.java:68) at Firstpack.Main.menu(Main.java:25) at Firstpack.Main.main(Main.java:82) </code></pre> <p>And I have no idea how to solve this. What is wrong here? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload