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 Organizing Data Serialization

Christopher David
PLUS
Christopher David
Courses Plus Student 20,027 Points

It's throwing an error about the Treet class. I believe I've set my package info accordingly. `

Both files are in com/teamtreehouse/ within Workspaces

Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
./com/teamtreehouse/Treets.java:20: error: class, interface, or enum expected
public static Treet[] load() {

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#@']+"); }

}

Treets.java package com.teamtreehouse;

import java.io.*;

public class Treets { 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(); }

} }

public static Treet[] load() { Treet[] treets = new Treet[0]; try ( FileInputStream fis = new FileInputStream("treets.ser"); ObjectInputStream ois = new ObjectInputStream(fis); ) { treets = (Treet[]) ois.readObject(); } catch(IOException ioe) { System.out.println("Error reading file"); ioe.printStackTrace(); } catch(ClassNotFoundException cnfe) { System.out.println("Error loading treets"); cnfe.printStackTrace(); } return treets;

}

Christopher David
Christopher David
Courses Plus Student 20,027 Points

I realized that the method was out of the class and adjusted the curly brackets accordingly.

1 Answer

Christopher David
PLUS
Christopher David
Courses Plus Student 20,027 Points

I realized that the method was out of the class and adjusted the curly brackets accordingly.