Help: Bank Statement Program, Objects within Object wrapper, null pointer
I am trying to create a class to create a list of banking transactions. The list should hold the date and time of the transaction, the type of transaction (either deposit or withdrawal) and the amount of the transaction.
So I came up with this code:
import java.util.*;
import java.text.*;
import java.util.LinkedList;
public class Transaction
{
class transactionTypeWrapper{
Date now;
StringBuffer transactionType = new StringBuffer(8);
int amount;
}
transactionTypeWrapper aTransaction;
public Transaction()
{
LinkedList transactions = new LinkedList();
}
public void addTransaction(String transactionType, int amount)
{
StringBuffer temp = new StringBuffer(transactionType);
aTransaction.transactionType.insert(0, "Deposit");
aTransaction.amount = amount;
System.out.println("Transaction Successful");
}
}
Whenever I try to execute the addTransaction method however, it throws up a NullPointerException. i think it has problems with my putting a StringBuffer inside the transactionTypeWrapper but I don't know any other way to do what I want to do without doing this?

