I am getting the following error when trying to compile my program.
'(' or '[' Expected.
public AccountArrayList()
{
// line one below is the hi-lighted code
ArrayList accounts = new ArrayList;
accounts.add("1");
accounts.add("1");
accounts.add("1");
accounts.add("1");
accounts.add("1");
accounts.add("1");
accounts.add("1");
accounts.add("1");
accounts.add(5,"900");
}
Thank you.
The class interface or enum expected error is a compile-time error in Java which arises due to curly braces. Typically, this error occurs when there is an additional curly brace at the end of the program.
class' expected. public class Calculator{ public Calculator(){ } public int sum(int one, int two) { int s = one + two; return int s; } } This error usually means that you are trying to declare or specify a variable type inside of return statement or inside of a method calls.
The error you're getting is stating that it expected to get an expression it could evaluate. Instead it sees that you are trying to make a variable assignment in your if statement.
You're missing parenthesis on the constructor:
ArrayList accounts = new ArrayList();
Your constructor is wrong. It has to be;
ArrayList accounts = new ArrayList();
If you are using Java 5 and higher, you will see that ArrayList
uses generics.
You can essentially to this:
ArrayList<String> accounts = new ArrayList<String>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With