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 Using ArrayLists

Compiling errors !

I'm having compiling errrors with the code and i'm not being able to get it right. The errors tell :

D:\JavaTreehouse>javac ExampleTreet.java .\com\treehouse\Treet.java:8: error: '{' expected public class Treet implements Comparable(Treet),Serializable ^ .\com\treehouse\Treet.java:8: error: Treet is not abstract and does not override abstract method compareTo(Object) in Comparable public class Treet implements Comparable(Treet),Serializable ^ .\com\treehouse\Treet.java:29: error: method does not override or implement a method from a supertype @Override ^

I would appreciate it if someone who already did it, provides me with the code of this exercise so i can tell where i'm wrong.

Thank you :)

Kourosh Raeen
Kourosh Raeen
23,733 Points

Can you post your code please?

2 Answers

Kourosh Raeen
Kourosh Raeen
23,733 Points

The line:

public class Treet implements Comparable(Treet),Serializable

should be:

public class Treet implements Comparable<Treet>, Serializable

Oh man i'm feeling so dumb now, how did i not see that :(

Thank you so much, you are a life saver :)

<p>


import com.treehouse.Treet;
// import com.treehouse.Treets;
import java.util.Date;
import java.util.Arrays;

public class ExampleTreet
{
    public static void main(String args [])
    {
        Treet treet=new Treet("EnesAli", "How u doing !", new Date (1456406139000L));
        System.out.printf("This is a new Treet : %s \n",treet);

        Treet secondTreet = new Treet("journeytocode","@treehouse makes learning Java sooooo fun! #treet",new Date(1421878767000L));

        System.out.println("The words are: ");
        for(String word : treet.getWords() )
        {
            System.out.println(word);
        }

        Treet[] treets = {secondTreet,treet};
        Arrays.sort(treets);
        for(Treet exampleTreet : treets)
        {
            System.out.println(exampleTreet);
        }

        /* Treets.save(treets); 
        Treet[] reloadedTreets = Treets.load();
        for(Treet reloaded : reloadedTreets)
        {
            System.out.println(reloaded);
        } */

        Treet originalTreet = treets[0];
        System.out.printf("Hashtags : ");
        for(String hashtag : originalTreet.getHashTags())
        {
            System.out.println(hashtag);
        }


    }
}







package com.treehouse;
import java.util.Date;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;

public class Treet implements Comparable(Treet),Serializable
{
     private static final long serialVersionUID = -8346695804890283872L;
    private boolean mBreakIt=true;
    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 "Treet : \"" + mDescription + "\"-@" + mAuthor + " "+ mCreationDate;
    }
    @Override
    public int compareTo(Treet other)
    {
        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 List<String> getWords()
    {
        String[] words =mDescription.toLowerCase().split("[^\\w@#']+");
        return Arrays.asList(words);
    }

    private List<String> getWordsPrefixedWith(String prefix)
    {
        List<String> results = new ArrayList<String>();
        for(String word : getWords())
        {
            if (word.startsWith(prefix))
            {
                results.add(word);
            }
        }
        return results;
    }

    public List<String> getHashTags()
    {
        return getWordsPrefixedWith("#");
    }

    public List<String> getMentions()
    {
        return getWordsPrefixedWith("@");
    }

}


</p>```

I commented the treets class and everything that had to do with since i think we don't need it anymore and it was showing me more errors with it anyway !

Sorry i'm not being able to correctly format it :(

Kourosh Raeen
Kourosh Raeen
23,733 Points

Click on the Markdown Cheatsheet link below and you see an example of how to format code. The example is for html, so just change the word html to java.

I did but it's not helping, i did it like it said " '''java <p> body </p> ''' "

Kourosh Raeen
Kourosh Raeen
23,733 Points

The problem is you are using ' instead of `.

Thank you :) I did it now