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 trial

Java Java Data Structures - Retired Efficiency! Changing Course

Vaibhav Yaramwar
PLUS
Vaibhav Yaramwar
Courses Plus Student 4,292 Points

Getting Error whole slving Quiz

I am getting Error while solving Quiz even though I have added Video in LIst :

Error : Bummer! Looks like you didn't 'add' the new video to the List

com/example/model/Course.java
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;
  }

}
com/example/model/Video.java
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;
  }

}
QuickFix.java
import com.example.model.Course;
import com.example.model.Video;

import java.util.Map;
import java.util.List;
import java.util.ArrayList;

public class QuickFix {

  public void addForgottenVideo(Course course) {

    List<Video> listvideo = new ArrayList<Video>();

    // TODO(1):  Create a new video called "The Beginning Bits"

       Video video = new Video("The Beginning Bits");
         listvideo.add(video);

    // TODO(2):  Add the newly created video to the course videos as the second video.
       course = new Course("The Beginning Bits",listvideo);
  }

  public void fixVideoTitle(Course course, String oldTitle, String newTitle) {

  }

  public Map<String, Video> videosByTitle(Course course) {
    return null;
  }

}

3 Answers

Chris Jones
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Jones
Java Web Development Techdegree Graduate 23,933 Points

Hey Vaibhav,

You did add the video to a list, but it wasn't the course's list. The instructions say that you should add the new video to to the second index in the course's list of videos (index 1). When you create a new array and add the video, then pass it to a the constructor, you've lost the video that was already a part of that course object. Does that make sense?

Here's how you maintain the course's current video list and just add the new video.

Let me know if you have any more questions.

public void addForgottenVideo(Course course) {
    // 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.
    course.getVideos().add(1, video);
  }
Vaibhav Yaramwar
PLUS
Vaibhav Yaramwar
Courses Plus Student 4,292 Points

Hey Chris....Sorry that was my silly mistake and you Identified correctly ....Thank You

You should not create a new list of Videos in the addForgottenVideo method. You need to create a new video (as you have done in the first step) but do not add the video to anything in this step.

In the second step, you need to get the list of videos contained in the Course object passed into the addForgottenVideo method (use the method for getting videos on the Course object) and then add the video you created in the first step to the list of videos you just retrieved with the getter. Note that the step requires you to add the video as the second video. This will require you to use a slightly different version of the .add method which will take an index as well as the video to add.