How do I calculate size of a file that contains bank accounts?

45 views Asked by At

I'm getting a nullpointerexception in my program and can't figure it out. These are the portions of code it is highlighting.

public int size()

         throws IOException
   {
      return (int) (file.length() / RECORD_SIZE);
   }

public int find(int accountNumber)
         throws IOException
   {
      for (int i = 0; i < size(); i++)
      {
         file.seek(i * RECORD_SIZE);
         int a = file.readInt();         
         if (a == accountNumber) { return i; }
            // Found a match            
      } 
      return -1; // No match in the entire file
   }

I believe this line is the main problem but don't really know what to do.

 int position = data.find(accountNumber);

Exception in thread "main" java.lang.NullPointerException
    at BankData.size(BankData.java:43)
    at BankData.find(BankData.java:79)
    at BankSimulator.main(BankSimulator.java:35)

If you need any other parts of my code to look at just let me know. The purpose of the program is to create a file, create bank accounts and/or delete them. It will then calculate the file size before and after a transaction. Thanks!

0

There are 0 answers