Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAndre Kucharzyk
4,479 PointsWhat am I doing wrong?
I get compiler error after I submit first task. First task is to initialise a Set of Strings. What am I doing wrong?
JavaTester.java:67: error: constructor Course in class Course cannot be applied to given types; Course course = new Course("Java Data Structures"); ^ required: String,Set found: String reason: actual and formal argument lists differ in length Note: JavaTester.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error
package com.example.model;
import java.util.List;
import java.util.Set;
public class Course {
private String mTitle;
private Set<String> mTags;
public Course(String title, Set<String> tags) {
mTitle = title;
// TODO: initialize the set mTags
mTags = tags;
}
public void addTag(String tag) {
// TODO: add the tag
}
public void addTags(List<String> tags) {
// TODO: add all the tags passed in
}
public boolean hasTag(String tag) {
// TODO: Return whether or not the tag has been added
return false;
}
public String getTitle() {
return mTitle;
}
}
1 Answer
Yanuar Prakoso
15,196 PointsHi Andre....
The challenge asked you to initialize a Set of Strings called mTags. You need to make brand new empty Set and wrapped it with HashSet or TreeSet to be able to process in future challenge. The initialization will create new empty HashSet or TreeSet which designed to accept Strings in the future. Thus the code should be like:
package com.example.model;
import java.util.List;
import java.util.Set;
import java.util.HashSet;//<- don't forget to import this HashSet class is not included as object by default in Java compiler
public class Course {
private String mTitle;
private Set<String> mTags;
public Course(String title, Set<String> tags) {
mTitle = title;
// TODO: initialize the set mTags
// mTags = tags;<- this is assigning, what you need to do is initializing new empty HashSet for future usage
mTags = new HashSet<String>(); //<- this is how you should initialize the Set
}
I hope this can help a little. Happy coding