Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to add Objects to my arraylist but its not working and its giving me

"Multiple markers at this line - Syntax error on token(s), misplaced construct(s) - Syntax error on token "a", VariableDeclaratorId expected after this token"

ArrayList<Record> records = new ArrayList<Record>();  
Record a = new Record ("Math","Add","Due Date is", "20/12/2011"); 
Record b = new Record ("Science","biology","Due Date is ", "21/12/2011"); 
records.add(a);
records.add(b);
share|improve this question
    
Please supply more context - where is this code? inside a method? outside a method? –  MByD Nov 3 '11 at 10:25
1  
The problem is not with adding to ArrayList rather than with instantiating objects. Can you please provide more information about the Record class? –  Egor Nov 3 '11 at 10:26
    
Its an syntax error, it has nothing to do with the list. –  Ralph Nov 3 '11 at 10:27
    
no its not inside any method ! this code is right after i declared the class and extended the Activity –  iyad al aqel Nov 3 '11 at 10:29
    
The class Record is a normal class , 4 string variables . one constructor that initialize those variables , getters and setters –  iyad al aqel Nov 3 '11 at 10:30

2 Answers 2

You need to put those calls to ArrayList.add() into a method!

See the answers to this question: What does the "Multiple markers" mean?

share|improve this answer

Put this code in onCreate() of Activity.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.