Reputation: 2758
ArrayList transactions = new ArrayList<Transaction>();
public void printTransactions() {
for(Transaction t: transactions)
System.out.println("Transaction Type: " + t.getType() +
"\nDescription: " + t.getDescription() +
"\nAmount: " + t.getAmount() +
"\nNew Balance: " + t.getBalance() +
"\nDate: " + t.getDate());
}
I'm new to Java and I have spent quite some time trying to figure out this error. In my printTransactions()
method, it says starting with the for loop line "Error: Incompatible types required Transaction found Object"
What I have tried is cast t
to a transaction class Transaction(t).getType()
but that has not helped either.
Upvotes: 0
Views: 684
Reputation: 24423
You are missing the generic type in transactions
declaration. Try this
ArrayList<Transaction> transactions = new ArrayList<Transaction>();
Upvotes: 6