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 Interfaces

David Sampimon
David Sampimon
12,026 Points

Cannot find symbol error, whilst my code appears to be the same as in the video

I have been comparing my code to the video and I simply cannot find where I am making a mistake. During compiling I get the following error:

Example.java:25: error: cannot find symbol
Arrays.sort(treets);
^
symbol: variable Arrays
location: class Example
1 error

Below is a copy of my code:

import java.util.Date;

import com.teamtreehouse.Treet;

public class Example {
  public static void main(String[] args) {
    Treet treet = new Treet(
      "craigsdennis",
      "Want to be famous? Simply tweet about Java and use the hashtag #treet" +
      "I'll use your tweet in a new" +
      "Bla bla bla",
      new Date(1421851405000L)   
    );  
    Treet secondTreet = new Treet(
      "journeytocode",
      "@treehouse makes learning Java sooooo fun! #treet",
      new Date(1421878767000L)
    );
    System.out.printf("This is a new Treet: %s %n", treet);
    System.out.println("The words are:");
    for (String word: treet.getWords()) {
      System.out.println(word);
  }
    Treet[] treets = {treet, secondTreet};
    Arrays.sort(treets);
     for (Treet exampleTreet : treets) {
     System.out.println(exampleTreet);
    }
  }      
}

3 Answers

Yeah, you need:

import java.util.Arrays;

at the top of your Example.java file.

Steve.

Do you need an import for Arrays? (I'm checking!!)

Steve.

David Sampimon
David Sampimon
12,026 Points

O snap! Thank you so much Steve. I have been going slightly mad staring at that line 25, completely overlooked the import.

Easy to overlook! Glad you got it sorted. :+1: :smile: