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

Java Java Objects (Retired) Harnessing the Power of Objects Exceptions

where is the get.Message() in the PezDispenser and dont see error in my code

public class Example {

public static void main(String[] args) {
    // Your amazing code goes here...
    System.out.println("We are makin a new Pez Dispenser");
  PezDispenser dispenser = new PezDispenser("miguel");
  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("Ate all th PEAZ!"); } 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 ex) { System.out.println("whoa there"); System.out.println("the error was: %s\n", ex.getMessage()); } } }

2 Answers

Kelly Hughes
Kelly Hughes
2,444 Points

Hey Kevin,

I'm new at Java as well, but I may be able to help.

So there are certain classes and static methods that we are able to access through specific Java packages. The .getMessage() method is from the java.lang package, and I believe this package is already accessible without the need to declare anything. For example, we don't have to create a System class to use System.out.println because the package that contains this class has already been imported for us (java.lang).

that help me a lot kelly

Kelly Hughes
Kelly Hughes
2,444 Points

Thanks, I'm happy that I could help!