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 trialDoug Hudson
979 PointsCant figure this one out...
public class Example {
public static void main(String[] args) {
// Your amazing code goes here...
System.out.println("We are making a new Pez Dispenser.");
PezDispenser dispenser = new PezDispenser();
System.out.printf("The dispenser character is %s\n",
dispenser.mCharacterName);
}
}
Error keeps referring to the following line: PezDispenser dispenser = new PezDispenser();
Any ideas?
Seth Kroger
56,414 PointsWhat is your PezDispenser.java code?
Doug Hudson
979 PointsIt says the error is in this line of code Keeps having an arrow pointing to the capital P in "PezDispenser();
PezDispenser dispenser = new PezDispenser();
Doug Hudson
979 PointsSays cannot find Symbol..yet im typing it exactly as shown in video..
Doug Hudson
979 Pointspublic class Example {
public static void main(String[] args) {
// Your amazing code goes here...
System.out.println("We are making a new Pez Dispenser.");
PezDispenser dispenser = new PezDispenser();
System.out.printf("the dispenser character is %s\n",
dispenser.mCharacterName);
}
}
there is my code....
Seth Kroger
56,414 PointsYou're supposed to have a 2nd file called PezDispenser.java that defines and implements the PezDispenser class. If you don't have it that's probably what's causing the trouble.
Doug Hudson
979 PointsPezDispenser.Java
public class PezDispenser { public String mCharacterName - "Yoda"; }
Doug Hudson
979 Pointspezdispenser.java
Doug Hudson
979 PointsI got it finally! lol
Seth Kroger
56,414 PointsAwesome!
3 Answers
Seth Kroger
56,414 PointsThe constructor for PezDispenser is supposed to be passed a String for the name of the character. You're getting that error because there is a mismatch in argument types.
Seth Kroger
56,414 PointsOK, you're a bit earlier along than I thought. The issue is the statement:
public String mCharacterName - "Yoda";
The minus sign should be an equals.
Doug Hudson
979 PointsI fixed that but im still getting the same error message.....
public class PezDispenser { public String mCharacterName = "Yoda"; }
public class Example {
public static void main(String[] args) {
// Your amazing code goes here...
System.out.println("We are making a new Pez Dispenser.");
PezDispenser dispenser = new PezDispenser();
System.out.printf("the dispenser character is %s\n",
dispenser.mCharacterName);
}
}
Seth Kroger
56,414 PointsIs the file for PezDispenser named "PezDispenser.java" or "PezDispenser.Java"? (the first is correct, the 2nd isn't)
Omh MG
19,233 PointsI am getting the same error in the console. Any solutions? Both of my files are Example.java and PezDispenser.java.
Example.java code:
public class Example {
public static void main(String[] args) {
// Your amazing code goes here...
System.out.println("We are making a Pez Dispenser.");
PezDispenser dispenser = new PezDispenser();
System.out.printf("The dispenser character is %s\n",
dispenser.mcharacterName);
}
}
PezDispenser.java code:
public class Example { public String mcharacterName = "Yoda"; }
Console error:
./PezDispenser.java:1: error: class Example is public, should be declared in a file named Example.java
public class Example {
^
Example.java:6: error: cannot access PezDispenser
PezDispenser dispenser = new PezDispenser();
^
bad source file: ./PezDispenser.java
file does not contain class PezDispenser
Please remove or make sure it appears in the correct subdirectory of the sourcepath.
2 errors
Nicolás LavÃn
1,922 Pointsyep, you have to put public before class PezDispenser {}
Doug Hudson
979 PointsDoug Hudson
979 PointsIm sorry...I guess I don't follow what your saying....I just did everything that he did...or at least I thought, just trying to figure out what doesn't matchup