0

We're beginners at Java so please don't give too advanced answers.

We're currently working on a school project and we're stuck. The purpose with the code is to add an event to an ArrayList but we keep getting an error every time we use add, not just in this part of the code.

Thankful for any answer

/Evangelina

5
  • 2
    Where do you define eventList? Commented Jan 9, 2018 at 14:23
  • 1
    You cannot add an Event to a List<String> that you defined as only holding Strings Commented Jan 9, 2018 at 14:24
  • And if eventList is ArrayList<String> then it isn't going to accept anything but a string. And seeing as you can't extend string, you're going to have to insert a string not an Event. Commented Jan 9, 2018 at 14:25
  • Also for( String eventList : set ) you cannot reuse the name of a list as a string variable, you might want to change it to eventName or such. Commented Jan 9, 2018 at 14:25
  • @svasa not true: ideone.com/0nuY0L eventList is defined outside the method, so you can both use that field in the method, and define a variable of the same name. (But can != should). Commented Jan 9, 2018 at 14:38

1 Answer 1

1

eventList is declared as a List<String>, which means you can only add instances of String to it.

If you want to store Events in your list, you should declare it as a List<Event>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.