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 trialAdmire Dhodho
5,411 PointsHow do i deal with this challenge?
Let's add a method that returns a list of all links in the body of the document. All words that start with http should be considered links. Name it getExternalLinks.
NOTE: Remember to import the needed classes from java.util. HINT: We already made the getWords method, we should use it!
package com.example;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class BlogPost implements Comparable<BlogPost>, Serializable {
private String mAuthor;
private String mTitle;
private String mBody;
private String mCategory;
private Date mCreationDate;
public BlogPost(String author, String title, String body, String category, Date creationDate) {
mAuthor = author;
mTitle = title;
mBody = body;
mCategory = category;
mCreationDate = creationDate;
}
public int compareTo(BlogPost other) {
if (equals(other)) {
return 0;
}
return mCreationDate.compareTo(other.mCreationDate);
}
public String[] getWords() {
return mBody.split("\\s+");
}
public List<String> getExternallinks(){
List<String> results = new ArrayList<String>();
for(String word: getWords()){
if (word.startsWith("http")){
results.add(word);
}
}
return results;
}
// return Stringlist,make a new list,loop, compare, add to our list finally return results
public String getAuthor() {
return mAuthor;
}
public String getTitle() {
return mTitle;
}
public String getBody() {
return mBody;
}
public String getCategory() {
return mCategory;
}
public Date getCreationDate() {
return mCreationDate;
}
}
3 Answers
Brian OLeary
16,197 PointsGreetings Admire,
Nice answer to the challenge!
If you happened to receive and error when you selected the green Check Work button, Similar to: (X) Bummer! Did you forget to add the getExternalLinks method?
The Challenge Craig posed - requests the method be named getExternalLinks.
We both made the same (error)->"learning experience!!!" of naming the method getExternallinks. Correct spelling, slightly mistyped lowercase letter l. Change lowercase l to Uppercase L in your method name.
If you change the line:
public List<String> getExternallinks(){
to the line:
public List<String> getExternalLinks(){
It will hopefully work for you.
Happy coding!!
Craig Dennis
Treehouse TeacherLooks good...what is the error?
Ashenafi Ashebo
15,021 PointsThe error was simple one, he uses getExternallinks() instead of getExternalLinks().
Khaidem Sandip Singha
Front End Web Development Techdegree Student 17,574 PointsCraig Dennis Feels good that even our instructor can miss pointing out such errors.
Andrew Winkler
37,739 Pointsmake sure you include all the import statements from the beginning of the video. Otherwise your your gonna get compiler errors because the blog class doesn't have access to the type of objects your trying to use. They are as follows:
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;