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 Efficiency! Add tags to a course

grahampaul
grahampaul
1,865 Points

On the first task, I get an error with code that is not present (on line 67). Not enough chars to paste the error.

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

This code doesn't exist!

com/example/model/Course.java
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;
    mTags = tags;
    // TODO: initialize the set mTags
  }

  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;
  }

}

2 Answers

Hi Graham,

The code it is referring to is the code that runs behind the scenes to test that you've addeed the correct code to the challenge. In this instance, it is calling the constructor for the Course class and is finding an error. That's because you have amended the constructor to take a String and a Set of String. It is expecting it just to take a String` object, in this case, "Java Data Structures".

The first task asks you to initialize the Set in the constructor. You don't need to pass it in to do that; you just want to assign something to it inside there. Take that parameter out of the constructor so that it just takes the single string parameter.

The member variable mTags is a Set but you'll want to initialize it as a HashSet. First, add the HashSet to the imports:

import java.util.HashSet;

Then, inside the constructor, assign a new HashSet to mTags:

mTags = new HashSet<String>();

That should do it for the first task.

Steve.

grahampaul
grahampaul
1,865 Points

Thanks Steve. My error is now obvious!

No problem. As long as you got through. :+1: