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 trialLeen Leenaerts
1,096 PointsEverytime I try to improve it I'm only getting more errors
./com/example/BlogPost.java:47: error: illegal start of type return words; ^ ./com/example/BlogPost.java:47: error: ';' expected return words; ^ ./com/example/BlogPost.java:50: error: class, interface, or enum expected public String getAuthor() { ^ ./com/example/BlogPost.java:52: error: class, interface, or enum expected } ^ ./com/example/BlogPost.java:54: error: class, interface, or enum expected public String getTitle() { ^ ./com/example/BlogPost.java:56: error: class, interface, or enum expected } ^ ./com/example/BlogPost.java:58: error: class, interface, or enum expected public String getBody() { ^ ./com/example/BlogPost.java:60: error: class, interface, or enum expected } ^ ./com/example/BlogPost.java:62: error: class, interface, or enum expected public String getCategory() { ^ ./com/example/BlogPost.java:64: error: class, interface, or enum expected } ^ ./com/example/BlogPost.java:66: error: class, interface, or enum expected public Date getCreationDate() { ^ ./com/example/BlogPost.java:68: error: class, interface, or enum expected } ^ ./com/example/BlogPost.java:36: error: cannot find symbol List httpList = new ArrayList(); ^ symbol: class ArrayList location: class BlogPost ./com/example/BlogPost.java:38: error: cannot find symbol if (word.startWith("http")) { ^ symbol: method startWith(String) location: variable word of type String Note: JavaTester.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 14 errors
package com.example;
import java.io.Serializable;
import java.util.Date;
import java.util.Arrays;
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> words = Arrays.asList(getWords());
List <String> httpList = new ArrayList<String>();
for (String word : words){
if (word.startWith("http")) {
httpList.add(word);
}
}
return httpList;
}
return words;
}
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;
}
}
2 Answers
Jon Kussmann
Courses Plus Student 7,254 PointsIn the middle of your code you have:
return words;
}
Go ahead and delete those two lines (including the bracket). Things should be working better from there.
Leen Leenaerts
1,096 Points./com/example/BlogPost.java:32: error: cannot find symbol public List getExternalLinks() { ^ symbol: class List location: class BlogPost ./com/example/BlogPost.java:33: error: cannot find symbol List words = Arrays.asList(getWords()); ^ symbol: class List location: class BlogPost ./com/example/BlogPost.java:33: error: cannot find symbol List words = Arrays.asList(getWords()); ^ symbol: variable Arrays location: class BlogPost ./com/example/BlogPost.java:34: error: cannot find symbol List httpList = new ArrayList(); ^ symbol: class List location: class BlogPost ./com/example/BlogPost.java:34: error: cannot find symbol List httpList = new ArrayList(); ^ symbol: class ArrayList location: class BlogPost Note: JavaTester.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 5 errors
still getting these errors
Leen Leenaerts
1,096 PointsLeen Leenaerts
1,096 PointsThanks, no idea how it got there
Still Giving mostly the same errors now for the part :
public List <String> getExternalLinks() { List <String> words = Arrays.asList(getWords()); List <String> httpList = new ArrayList<String>(); for (String word : words){ if (word.startWith("http")) { httpList.add(word); } } return httpList; }
Jon Kussmann
Courses Plus Student 7,254 PointsJon Kussmann
Courses Plus Student 7,254 PointsTry "startsWith" instead of "startWith"