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 trialJulie Heckleman
Courses Plus Student 11,412 PointsError: Cannot find symbol on save(Treet[] treets)
I am just using CMD line. Tried using NetBeans and still got this error.
Treets.java
package com.teamtreehouse;
import java.io.*;
public class Treets { // THIS LINE BELOW IS WHERE I GET 'Cannot find symbol Treet' public static void save(Treet[] treets) { try ( FileOutputStream fos = new FileOutputStream("treets.ser"); ObjectOutputStream oos = new ObjectOutputStream(fos); ) { oos.writeObject(treets); } catch(IOException ioe) { System.out.println("Problem saving Treets"); ioe.printStackTrace(); } } }
Treet.java
package com.teamtreehouse;
import java.io.Serializable; import java.util.Date;
public class Treet implements Comparable, Serializable { private String mAuthor; private String mDescription; private Date mCreationDate;
public Treet(String author, String description, Date creationDate){
mAuthor = author;
mDescription = description;
mCreationDate = creationDate;
}
@Override
public String toString() {
return String.format("Treet: \"%s\" by %s on %s", mDescription, mAuthor, mCreationDate);
}
@Override
public int compareTo(Object obj) {
Treet other = (Treet) obj;
if (equals(other)) {
return 0;
}
int dateCmp = mCreationDate.compareTo(other.mCreationDate);
if (dateCmp == 0) {
return mDescription.compareTo(other.mDescription);
}
return dateCmp;
}
public String getAuthor() {
return mAuthor;
}
public String getDescription() {
return mDescription;
}
public Date getCreationDate() {
return mCreationDate;
}
public String[] getWords() {
return mDescription.toLowerCase().split("[^\\w#@']+");
}
}
2 Answers
Pedro Cabral
33,586 PointsIt looks like Treet is complaining that it doesn't know what Treet is. Have you double checked if they both belong to the same package? Because in case they are in different packages, Treet needs to be imported into Treets.
Julie Heckleman
Courses Plus Student 11,412 PointsAlright I answered my own question. FYI all my packaging info and imports are correct within my code. I was trying to compile my Treet.java and Treets.java files on their own. When I compiled Example.java it ended up taking care of it.
Also just to clarify for anyone after me, I am using Windows cmd line, not Treehouse Workspaces. It's a little bit different.