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!
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
Unsubscribed User
3,091 PointsExceptions
This is my code for the Example.java file being worked on. Yet mine gives error messages.
Example.java:33: error: unclosed string literal
Example.java:33: error: no suitable method found for println(String,String)
System.out.println("The error was: %s\n", iae.getMessage());
^
method PrintStream.println() is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(boolean) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(char) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(int) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(long) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(float) is not applicable
(actual and formal argument lists differ in length)
Example.java:37: error: class, interface, or enum expected
}
^
1 error
Used Code below
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("Yoda");
System.out.printf("The dispenser character is %s\n",
dispenser.getCharacterName());
if (dispenser.isEmpty()) {
System.out.println("It is currently empty");
}
System.out.println("Loading...");
dispenser.load();
if (!dispenser.isEmpty()) {
System.out.println("It is no longer empty");
}
while (dispenser.dispense()) {
System.out.println("Chomp!");
}
if (dispenser.isEmpty()) {
System.out.println("Is currently empty");
}
dispenser.load(4);
dispenser.load(2);
while (dispenser.dispense()) {
System.out.println("Chomp!");
}
try {
dispenser.load(400);
System.out.println("This will never happen");
} catch (IllegalArgumentException iae) {
System.out.println("Whoa there!");
System.out.println("The error was: %s\n", iae.getMessage());
}
}
}
}
5 Answers

Steve Hunter
57,709 PointsYour error is exactly the same. As is your code:
Example.java:33: error: unclosed string literal
Example.java:33: error: no suitable method found for println(String,String)
System.out.println("The error was: %s\n", iae.getMessage());
Can you try changing the println
to printf
to see if that works. Line 33 has two strings passed into println
- it is expecting a single string. printf
can cope with multiple arguments as it handles formats.
Thanks,
Steve.

Steve Hunter
57,709 PointsHi Brendon,
I think you'll need to use printf
as you want to use a formatted string using %s
.
The argument lists differ as you have passed two strings into println
when it is expecting a single argument of various types.
System.out.printf("The error was: %s\n", iae.getMessage());
I hope that helps. Let me know how you get on.
Steve.

Unsubscribed User
3,091 PointsChanged, but getting the same error message.

Steve Hunter
57,709 PointsCan you paste the error output - it might help! We'll get to the bottom of this ....

Unsubscribed User
3,091 PointsThe error was posted in my first post.
Example.java:33: error: unclosed string literal Example.java:33: error: no suitable method found for println(String,String) System.out.println("The error was: %s\n", iae.getMessage()); ^ method PrintStream.println() is not applicable (actual and formal argument lists differ in length) method PrintStream.println(boolean) is not applicable (actual and formal argument lists differ in length) method PrintStream.println(char) is not applicable (actual and formal argument lists differ in length) method PrintStream.println(int) is not applicable (actual and formal argument lists differ in length) method PrintStream.println(long) is not applicable (actual and formal argument lists differ in length) method PrintStream.println(float) is not applicable (actual and formal argument lists differ in length) Example.java:37: error: class, interface, or enum expected } ^ 1 error

Unsubscribed User
3,091 PointsYea that was weird. I changed that, and the error ran again. Though now I ran again and it worked.
I guess it was just being weird. Thanks.

Steve Hunter
57,709 PointsGlad you got it fixed.
Steve.