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 trialKenneth Phillips
Courses Plus Student 10,188 Pointsset import problem
So here is the error:
./QuickFix.java:19: error: cannot find symbol
Set
Look at my code and please someone tell me the problem.
package com.example.model;
import java.util.List;
public class Course {
private String mName;
private List<Video> mVideos;
public Course(String name, List<Video> videos) {
mName = name;
mVideos = videos;
}
public String getName() {
return mName;
}
public List<Video> getVideos() {
return mVideos;
}
}
package com.example.model;
public class Video {
private String mTitle;
public Video(String title) {
mTitle = title;
}
public String getTitle() {
return mTitle;
}
public void setTitle(String title) {
mTitle = title;
}
}
import com.example.model.Course;
import com.example.model.Video;
import java.util.List;
import java.util.Set;
import java.util.HashMap;
import java.util.Map;
public class QuickFix {
public void addForgottenVideo(Course course) {
List<Video> newList = course.getVideos();
// TODO(1): Create a new video called "The Beginning Bits"
Video video = new Video("The Beginning Bits");
// TODO(2): Add the newly created video to the course videos as the second video.
newList.add(1, video);
}
public void fixVideoTitle(Course course, String oldTitle, String newTitle) {
Set<Video> allVideos = videosByTitle(course).valueSet();
for (Video video : allVideos) {
if (video.getTitle() == oldTitle) {
videosByTitle(course).remove(oldTitle, video);
videosByTitle(course).put(newTitle, video);
}
}
}
public Map<String, Video> videosByTitle(Course course) {
Map<String, Video> videoMap = new HashMap<String, Video>();
for (Video video : course.getVideos()) {
videoMap.put(video.getTitle(), video);
}
return videoMap;
}
}
3 Answers
Craig Dennis
Treehouse TeacherThe goal of this one is to pull out the course by the old title and then set the title properly on that course. Don't worry about modifying the collection, it gets generated each time.
Ker Zhang
Full Stack JavaScript Techdegree Graduate 29,113 PointsWhile running your code, I got same error and didn't know how to fix it. However, this solution for this challenge could be simplified in this way:
public void fixVideoTitle(Course course, String oldTitle, String newTitle) { videosByTitle(course).get(oldTitle).setTitle(newTitle); }
Craig Dennis
Treehouse Teachervideo.getTitle() == oldTitle
Remember that you must use the .equals
on objects.
Check out The Thing About Strings workshop for more information.
Kenneth Phillips
Courses Plus Student 10,188 PointsThanks but I still receive the same error even after I use the equals method.
Kenneth Phillips
Courses Plus Student 10,188 PointsKenneth Phillips
Courses Plus Student 10,188 PointsI forgot about the setTitle() method. Looks like I overthought it. Thanks for the help Craig Dennis. :)