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 trialHerbert Keijman
702 PointsWhat's wrong with this code? I'm getting too much compilaton errors
I'm getting a lot of errors just as in the previous exercises. What can I do about it and what is wrong with this code? It makes checking the answer and getting hints impossible.
thanks a lot!
public class Main {
public static void main(String[] args) {
GoKart kart = new GoKart("yellow");
if (kart.isBatteryEmpty()) {
System.out.println("The battery is empty");
}
try {
kart.drive(2);
} catch (IllegalArgumentExcpetion iae) {
System.out.println("not working");
System.out.println("the error was: %n\n", iae.getMessage());
}
}
}
4 Answers
hbdc
13,725 PointsHey there,
You have got quite a few errors:
- You have a typo on the IllegalArgumentExcpetion - has to be spelled IllegalArgumentException.
- Make sure you import java.lang.*;
- You need to use a printf instead of println.
- %n\n do pretty much the same depending on the OS. You need to use %s%n
- You have a closing bracket missing at the end.
Herbert Keijman
702 PointsThanks, I will try again!
Craig Dennis
Treehouse TeacherPut the cursor on the closing bracket, see how it highlights the on that opens it....looks like you might have an extra closing bracket. Common problem!
Stick with it! Looking good!
PS: Also good call on the spelling mistake Yani Kapitanov ! However, java.lang
is imported by default.
Jonathan Hector
5,225 PointsWhen you have to many errors, START with the first one on the list and then move down. Sometimes, the first one fixes the rest. Also a good spell check helps.