Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Meet Objects Creating Classes

println issues !

public class Example {

public static void main(String[] args) {

  System.out.println(" We're making a new Pez Dispenser \n");
  PezDispenser dispenser = new PezDispenser();
  System.out.println("The dispenser is called %s", dispenser.mCharacter);

} }

I got a whole lot of errors when I used println while printf worked fine. My PezDispenzer class is exactly the same as Craigs.

The first error I got was no suitable method found for println(String, String); followed by a whole list of others..

2 Answers

Kourosh Raeen
Kourosh Raeen
23,732 Points

You get errors because there is no println() method that takes two arguments. You need to use printf() for that last statement:

System.out.printf("The dispenser is called %s", dispenser.mCharacter);
Fernando Flores
seal-mask
.a{fill-rule:evenodd;}techdegree
Fernando Flores
Python Web Development Techdegree Student 720 Points

I was getting the same errors, even with printf. This is what I did. Not sure if it's correct, I'm a newbie with Java.

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.println("The dispenser character is " + dispenser.mCharacterName);
}

}