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 trialEwerton Luna
Full Stack JavaScript Techdegree Graduate 24,031 PointsI'm stuck in this challenge and I don't know why!
Please, can someone tell me what I'm doing wrong on my getExternalLinks method? I'm quite sure I did it right and it is similar to the code Craigs writes in the video!
package com.example;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
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;
}
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;
}
}
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! You're really close here. When you see a compiler error and it says it's on line 15 for example and you can't find anything at all wrong with line 15, start reading upwards in your code. It's very likely that something above it was incorrect. This is especially true when it says something was unexpected. It means that something before it didn't end the way it was supposed to.
That is what is happening here.
You wrote:
List<String> results = new ArrayList<String>
But you forgot both the ending semicolon and the parentheses. You meant to write:
List<String> results = new ArrayList<String>();
Hope this helps!
Ewerton Luna
Full Stack JavaScript Techdegree Graduate 24,031 PointsOh my god... I spent so much time looking for the error and I couldn't find this little thing lol You are awesome! I really liked your compiler tip to identify where the error is as well! Thank you very much!
Ewerton Luna
Full Stack JavaScript Techdegree Graduate 24,031 PointsEwerton Luna
Full Stack JavaScript Techdegree Graduate 24,031 PointsThe compiler is always telling me this, but I still don't understand what is wrong:
./com/example/BlogPost.java:36: error: '(' or '[' expected for (String word : getWords()){ ^ ./com/example/BlogPost.java:36: error: ')' expected for (String word : getWords()){ ^ ./com/example/BlogPost.java:36: error: not a statement for (String word : getWords()){ ^ ./com/example/BlogPost.java:36: error: ';' expected for (String word : getWords()){ ^ ./com/example/BlogPost.java:37: error: cannot find symbol if (word.startsWith("http")){ ^ symbol: variable word location: class BlogPost ./com/example/BlogPost.java:38: error: cannot find symbol results.add(word); ^ symbol: variable word location: class BlogPost Note: JavaTester.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 6 errors