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 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,733 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);
}

}