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

Broderic Crowe
Broderic Crowe
1,549 Points

"identifier expected" error?

Pretty sure my code is the same as Craig's but I'm getting 2 errors that I've implemented in this code below.

import java.util.Arrays;
import java.util.Date;

import com.teamtreehouse.Treet;

public class Example {

  public static void main(String[] args) {


    Treet treet = new Treet(
    "Brodericcrowe",
    "Example Treet from @Brodericcrowe.",
    new Date());


    Treet secondTreet = new Treet(
      "JourneyDude", 
      "Treehouse is fun, #treet",
      new Date());

    System.out.printf("This is a new treet:%n%s%n", treet);


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

  Treet[] treets = {treet, secondTreet}; 

  //error <identifier> expected 
  Arrays.sort(treets);
  //         ^      ^
}

This is the Treet.java file below. No errors here, just in case you see something that could be causing errors in Example.java file above.

package com.teamtreehouse;

import java.util.Date;

public class Treet {

  private String mAuthor;
  private String mDescription;
  private Date mCreationDate; 

  //constructor 
  public Treet(String author, String description, Date creationDate) {
    mAuthor = author;
    mDescription = description;
    mCreationDate = creationDate; }
  //end constructor 

  //Tweet formatter
  @Override
  public String toString() {
    return "Treet: \"" + mDescription + "\" - @" + mAuthor; }
  //end Tweet formater 


  //getters
  public String getAuthor() {
    return mAuthor; }

  public String getDescription() {
    return mDescription; }

  public Date getCreationDate() {
    return mCreationDate; }
  //end getters

  public String[] getWords() {

    return mDescription.toLowerCase().split("[^\\w#@']+");

  }

}

1 Answer

Broderic Crowe
Broderic Crowe
1,549 Points

Lol, found it. Just needed to put the Array inside the "main" code block, and not in the "Example" code block.