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 trialYael P.
2,816 PointsDeclaring new variable and got error "Cannot find symbol"
I've read all questions related to this, but still I can't figure out how to solve this.
My code - PezDispenser.java:
public class PezDispenser {
// creating an object with size 12
// final = no one can change this value
public final int MAX_PEZ = 12;
// private = if you are not the class you can access this use get method
private String mCharacterName;
// making a contractor with 1 argument
public PezDispenser(String characterName) {
// Use of "m" before characterName to define it as a member
mCharacterName = characterName;
}
// properties
public String getCharacterName() {
return mCharacterName;
}
// jave-repl
// :load - explore object by loading X.java file such as :load PezDispenser.java
}
Exmaple.java
public class Example {
public static void main(String[] args) {
// Your amazing code goes here...
System.out.println("We are a making a new Pez Dispenser.");
PezDispenser dispenser = new PezDispenser("Yael");
System.out.printf("This dispenser character is %s\n", dispenser.getCharacterName());
}
}
when using java-repl, loading works fine, creating new variable throw this error:
We are a making a new Pez Dispenser.
This dispenser character is Test
treehouse:~/workspace$ java-repl
Welcome to JavaREPL version 272 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_20)
Type expression to evaluate, :help for more options or press tab to auto-complete.
java> :load PezDispenser.java
Loaded source file from PezDispenser.java
java> PezDispenser pd = new PezDispenser("Yoda");
ERROR: cannot find symbol
symbol: class PezDispenser
location: interface Evaluation
PezDispenser method$9l7qv3fwog5xcmz8jehb();
^
Please help
3 Answers
Michael McDonald
2,877 PointsI think you uncovered a bug in the teamtreehouse java-repl. I got the same errors as you until I removed your //comments. Comments shouldn't matter but apparently the repl misread your code because of them.
Yael P.
2,816 PointsThank you, indeed it solved the problem :)
Chris Ramacciotti
Treehouse Guest TeacherAfter careful research, it appears that this is a bug in a third-party library we use for that REPL tool. I just found through a series of tests that a comment containing class
followed by a valid Java identifier wouldn't be parsed correctly with the :load
command. I've filed an issue here:
Soumyadeep Mukhopadhyay
1,772 PointsSoumyadeep Mukhopadhyay
1,772 PointsYou have been a savior. Thank you.