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 Getting There Type Casting

kabir k
PLUS
kabir k
Courses Plus Student 18,036 Points

I keep getting `cannot find symbol` error while importing

In the Type Casting video (01:05), after loading my Treet.java file like Craig does and tried to import the Treet class from its package, I keep getting cannot find symbol error.

My code is exactly the same as Craig's and everything has been working fine up until when I tried importing.

Does anyone have any idea what's going on?

Below is the error message I'm getting.

treehouse:~/workspace$ java-repl                                                                                                        
Welcomimport com.teamtreehouseTreet;                                                                                                    
Terminating...                                                                                                                          
treehouse:~/workspace$ java-repl                                                                                                        
Welcome to JavaREPL version 303 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_65)                                                      
Type expression to evaluate, :help for more options or press tab to auto-complete.                                                      
java> :load com/teamtreehouse/Treet.java                                                                                                
Loaded source file from com/teamtreehouse/Treet.java                                                                                    
java> import com.teamtreehouse.Treet;                                                                                                   
ERROR: cannot find symbol                                                                                                               
  symbol:   class Treet                                                                                                                 
  location: package com.teamtreehouse                                                                                                   
import com.teamtreehouse.Treet;;                                                                                                        
                        ^

Treet.java

package com.teamtreehouse; 

import java.util.Date;  

public class Treet {
  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; 
  }

  public String getAuthor() {
    return mAuthor;
  }

  public String getDescription() {
     return mDescription;
  }

  public Date getCreationDate() { 
    return mCreationDate;
  } 

} 

Example.java

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 " +
      "@treehouse course about data structures.",
      new Date(1421849732000L) 
    ); 
    System.out.printf("This is a new Treet:  %s %n", treet); 
  }                                

} 
Alper Ersoy
Alper Ersoy
1,281 Points

Probably there is something about your code, can you please show it?

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Kabir,

can you see a Treet.class file inside the teamtreehouse folder? Try to save and recompile the Treet.java. Maybe it will help.

Let us know if you could solve the issue.

kabir k
kabir k
Courses Plus Student 18,036 Points

Hi Grigorij,

Yes I can see the Treet.class file inside the teamtreehouse folder. And I have saved and recompiled the Treet.java file repeatedly but to no avail.

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

This is weird :(

Have you tried to reload the workspace and hit your PC really hard :) ?

Maybe this can help ...

kabir k
kabir k
Courses Plus Student 18,036 Points

I know and I have tried reloading the workspace over and over. This makes following along difficult when your program is not responding as it should.

2 Answers

Jordan Ernst
Jordan Ernst
5,121 Points

try implementing in your Treet Class Comparable. i can't remember but i think you need this for the Date import...

kabir k
kabir k
Courses Plus Student 18,036 Points

How do you do that? Besides, how come it works for Craig and not for me even though I followed exactly what he did?

Jordan Ernst
Jordan Ernst
5,121 Points

sorry this was incorrect i watched the video over and am aware this hasn't been taught yet

Jordan Ernst
Jordan Ernst
5,121 Points

it may sound silly but if your folders are all in correct levels. had you ensured to save your progress after you typed it up? if it times out and you never saved it your data will be lost. your error seems to say it is this"Treet;;" with 2 semicolons of course in your code that i see it is spelled correctly. maybe you had just forgotten to save after fixing this typo?

kabir k
kabir k
Courses Plus Student 18,036 Points

Thanks but I save every time I write code.