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.

anjitapanta
2,641 PointsI do not understand what Im doing wrong
Ive been stuck on this forever, I think this is the right code, but I cant get past it.
public class Main {
public static void main(String[] args) {
GoKart kart = new GoKart("yellow");
if (kart.isBatteryEmpty()) {
System.out.println("The battery is empty");
}
kart.drive(2);
try
{
kart.drive(200);
}catch(IllegalArgumentException iae)
{
System.out.println("The error was: %s", iae.getMessage());
}
}
}
2 Answers

Robert Richey
Courses Plus Student 16,352 PointsHi Anjita,
I see a couple issues with your code. The drive method is already being called - don't need to call it again. Wrap your try / catch block around kart.drive(2);
Also, when you catch the error, you're passing in a formatted string to println. Either just print iae
using println()
or change it to printf()
and your formatted string will work.
Kind Regards

anjitapanta
2,641 PointsI did printf, its still not working :(

Robert Richey
Courses Plus Student 16,352 PointsCan I get you to post the line of code that's using printf?

anjitapanta
2,641 Pointsprintf("The error was: %s", iae.getMessage());

Robert Richey
Courses Plus Student 16,352 PointsMake sure System.out is preceding printf
System.out.printf("The error was: %s", iae.getMessage());
If this still doesn't work for you, please post all of the code you're trying, from the challenge.
We'll get through this, I promise!
anjitapanta
2,641 Pointsanjitapanta
2,641 PointsI did printf, its still not working :(