title: java Runtime Date syntax error - easy fix?
body: <p>I'm trying to make it so each transaction is time stamped, but I'm having an issue with the date object. I keep running into a syntax error every time the program gets to the constructor. Any ideas?</p>
  
  <p>Thank you so much!!! </p>
  
  <h2>UPDATE: I changed it so the constructor class now says:</h2>
  
  <pre><code>DateFormat df = new SimpleDateFormat("MM/dd/yy HH:mm");
  Date dateobj = new Date();
  </code></pre>
  
  <p>But now I run into a null pointer expression as soon as it's called in the MainMenu method. How do I get it to work in all the methods like the array list?</p>
  
  <pre><code>/**
   * Bank Account
   * 
   * @author: Seth Killian
   * @version: 1.
   * @citations: All okay. Adapted online tutorials in using the scanner tools to create a menu and list array.
   */
  
  import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.Scanner;
  //import java.util.Calendar;
  
  public class BankAccount 
  { 
  
    private double minbalance; // Minimum allowable account balance
    private double maxdeposit; // Maximum allowable deposit
    private double balance; // Account balance 
    private double rate; // Rate of annual interest in value of percent
    private String AcctName; // Account name
    private ArrayList&lt;String&gt; transactions;
    public Date dateobj;
    public DateFormat df;
  
    /**
    * Constructor for Bank Account Class with Starting Balance
    * @param: Starting Balance
    * @return: None
    */
    public BankAccount(double startBalance) 
    {
      DateFormat df = new SimpleDateFormat("MM/dd/yy HH:mm");
      Date dateobj = new Date();
      transactions = new ArrayList&lt;String&gt;();
      balance = startBalance;
      transactions.add("+ $" + startBalance + " Initial Balance "  + df.format(dateobj) + " Bal: $" + balance);
      minbalance = 0.25;
      maxdeposit = 5000.00;
      rate = 6; // Six percent annual interest
      AcctName = "Seth Killian";
    }
  
    /**
    * Main Menu which allows the user to select from options 
    * @param: None
    * @return: None
    */
    public void MainMenu()
    {
      Scanner in = new Scanner (System.in);
      switch (in.nextInt())
      {
        case 0:
         Initialize();
        case 1:
         System.out.println("Balance: $" + balance + " as of " + df.format(dateobj));
         SelectOption();
  
        case 2: //Make a deposit        
         double amount;
         System.out.print("Deposit Amount: $");
         amount = in.nextDouble();
         if (!(amount &gt; 0) || (amount &gt; maxdeposit))
          {transactions.add("* Attempted Deposit: $" + amount + " "  + df.format(dateobj));}    
         if (!(amount &gt; 0))
          {System.out.println("Error: Amount must be greater than zero");}
         else if (amount &gt; maxdeposit)
          {System.out.println("Error: Maximum Deposit $" + maxdeposit + ".");} 
         else
          { 
            balance += amount;
            transactions.add("+ $" + amount + " Deposit "  + df.format(dateobj) + " Bal: $" + balance);
            System.out.println("Success: Deposited $" + amount + " Balance: $" + balance);
          }
         SelectOption();
  
        case 3: //Make a withdrawl
         System.out.print("Withdrawl Amount: $");
         amount = in.nextDouble();
         if (!(amount &gt; 0) || (amount &gt; balance) || (balance-amount &lt; minbalance))
          {transactions.add("* Attempted Withdrawl: $" + amount + " "  + df.format(dateobj));}    
         if (!(amount &gt; 0))
          {System.out.println("Error: Amount must be greater than zero");}
         else if (amount &gt; balance) 
          {System.out.println("Error: Insufficent Funds");}
         else if (balance-amount &lt; minbalance)
          {System.out.println("Error: Minimum Balance $" + minbalance + ".");}
         else 
          { 
           balance -= amount;
           transactions.add("- $" + amount + " Withdrawl "  + df.format(dateobj) + " Bal: $" + balance);
           System.out.println("Success: Withdrew $" + amount + " Balance: $" + balance);
          }
         SelectOption();
  
        case 4: //Apply Annual Interest
         balance = balance + (balance * (rate/100.0));
         transactions.add("Interest ("+ rate + "%) "+ df.format(dateobj) + " Bal: $" + balance);
         System.out.println("Success: " + rate + "% Interest rate applied. Balance: $" + balance);
         SelectOption();
  
        case 5: // Print Log
         System.out.println(); 
         System.out.println("Transaction Log for " + AcctName);
         System.out.println("---------------------------------------- ");
         for(int x = 0; x &lt; transactions.size(); x++)
          {System.out.println(transactions.get(x));}
         System.out.println("---------------------------------------- ");
         SelectOption();
  
        case 6: // Exits application
          System.exit(0);  
  
        default: // Unrecognized Selection
          System.out.println ("Error: Selection Unrecognized");
          SelectOption();
      }
    }
  
    /**
    * Sets the Main Menu up
    * @param: None
    * @return: None
    */
    public void Initialize()
    {
      System.out.print('\u000C'); // Clears the terminal screen
      System.out.println("Welcome " + AcctName + "!");
      System.out.println("======================================== "); 
      System.out.println("1) Check Balance\n2) Make a Deposit\n3) Make a Withdrawl\n4) Add Annual Interest\n5) Transaction Logs");
      System.out.println("\n0) Clear Screen\n6) Exit Application");
      System.out.println("======================================== "); 
      SelectOption();
    } 
  
    /**
    * Allows the user to make a selection.
    * @param: None
    * @return: None
    */
    public void SelectOption()
    {
      System.out.print ("Selection: ");
      MainMenu();
    }
  
  }
  </code></pre>