0
public class ReservationSystem {

   static Service p;
   public static void main(String[] args) {     
   String filename = null;
   if(args.length == 0)
   {
      System.out.println("Improper format: filename needed");
      System.exit(0);
   }
   filename = args[0];
   File a = new File(filename);
   try 
   {
     if (a.exists())
     {
       System.out.println("File already exist, will proceed to Menu");
       p.readfile(filename);
       menu();
     }
     else 
     {
       a.createNewFile();
       System.out.println("New file created, will proceed to Menu");
       menu();
     }
   }

I'm having null pointer exception when trying to pass filename into method of another class. the error is on this line p.readfile(filename);. Can someone suggest a way to fix this.I'm trying to debug this, but I don't understand why the system gave that error when I'm only trying to pass in a string, by the way, the file exist and I was able to trace it until the line of error.

KhoaVo
  • 376
  • 3
  • 18
  • 2
    Hint: Have you initialized your `Service` lately? – Makoto Sep 08 '15 at 19:21
  • Is `p` null at that point? You aren't assigning a value to that variable. The way to debug a NPE is to set a breakpoint on the line throwing the error and inspect the values to see what is null. – Mark B Sep 08 '15 at 19:22
  • damn it, you are right, I'm too sleepy to realize this, thank a lot for answering so quickly – KhoaVo Sep 08 '15 at 19:26

0 Answers0