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 - Retired Exploring the Java Collection Framework Sets

Michael Timbs
Michael Timbs
15,761 Points

loading the treets.ser file?

I am following this in Eclipse so have downloaded the project files and copied the treets.ser over to my project folder. When I try to use the Treet[] treets = Treets.load(); I get a tonne of compile time errors.

Any way around this?

Dan Johnson
Dan Johnson
40,533 Points

Can you list the errors and the project version (e.g. s3v1)?

Michael Timbs
Michael Timbs
15,761 Points

s3v5 is where I copied teh treets.ser from.

Error loading treets. java.lang.ClassNotFoundException: com.teamtreehouse.Treet at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at java.io.ObjectInputStream.resolveClass(Unknown Source) at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source) at java.io.ObjectInputStream.readClassDesc(Unknown Source) at java.io.ObjectInputStream.readArray(Unknown Source) at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown Source) at com.treehouse.Treets.load(Treets.java:14) at Example.main(Example.java:12)

This is how I am trying to load it:

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");
        } catch(ClassNotFoundException cnfe) {
            System.out.println("Error loading treets.");
            cnfe.printStackTrace();
        }
        return treets;
    }
Dan Johnson
Dan Johnson
40,533 Points

Did you happen to change the package that Treet and Treets were put in while copying the files?

Michael Timbs
Michael Timbs
15,761 Points

Yeah that would be it. My package is just called com.treehouse whereas workspaces called it com.treehouse.treets

I just had a look in the .ser file and it specifies the package directory (I think) so that would be why it cant load them. At least I know it isnt my code now but rather just a directory issue

Dan Johnson
Dan Johnson
40,533 Points

if you change the package declaration to

package com.teamtreehouse;

for Treet and Treets (and then have Eclipse refactor) it should load the file without issue.