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) Harnessing the Power of Objects Handling Exceptions

Herbert Keijman
Herbert Keijman
702 Points

What'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!

Main.java
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

Hey there,

You have got quite a few errors:

  1. You have a typo on the IllegalArgumentExcpetion - has to be spelled IllegalArgumentException.
  2. Make sure you import java.lang.*;
  3. You need to use a printf instead of println.
  4. %n\n do pretty much the same depending on the OS. You need to use %s%n
  5. You have a closing bracket missing at the end.
Herbert Keijman
Herbert Keijman
702 Points

Thanks, I will try again!

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Put 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
Jonathan Hector
5,225 Points

When 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.