I created a diretory and put the following files in the directory: Virtual Person.java and coffeecup.java(p.3),temperatureexception.java, toocoldexception.java, and toohotexception.java(p7). I then compiled the programs, but when I run virtualperson.java, I get the following error message: VirtualPerson.java:10: cannot find symbol symbol : constructor TooColdException() location: class TooColdException throw new TooColdException(); ^ VirtualPerson.java:13: cannot find symbol symbol : constructor TooHotException() location: class TooHotException throw new TooHotException(); ^ 2 errors
Would anyone be able to shed light on this. Both TooHotException and TooHotException contain their respective constructors and both files as indicated above are in the same directory. The case of the names is the same as the article, I can find no upper/lower case name differece. So, why can't the JVM find TooHot and Too ColdException?
I looked at the code and it appeared that the classes toohot and toocold needed an argument, so I put temperature in as a parameter in virtualperson.java. For example: if (temperature <= tooCold) { throw new TooColdException(temperature);
But, now I get the following compile message: java.lang.NoSuchMethodError: main Exception in thread "main"
> I looked at the code and it appeared that the classes > toohot and toocold needed an argument, so I put > temperature in as a parameter in virtualperson.java. For > example: > if (temperature <= tooCold) { > throw new TooColdException(temperature); > > But, now I get the following compile message: > java.lang.NoSuchMethodError: main > Exception in thread "main" > > So, obviously that wasn't the solution.
Maybe the problem is that the names of your files are all lower case. The compiler does look for files that match the class names, case included.
VirtualPerson.java:7: cannot find symbol symbol : constructor TooHotException() location: class TooHotException throw new TooHotException(); ^ VirtualPerson.java:9: cannot find symbol symbol : constructor TooColdException() location: class TooColdException throw new TooColdException(); ^ 2 errors
Here is the code from: VirtualPerson.java: class VirtualPerson { public void drinkCoffee(CoffeeCup cup) { try { int i = (int) (Math.random() * 4.0); switch (i) { case 0: throw new TooHotException(); case 1: throw new TooColdException(); case 2: throw new UnusualTasteException(); default: System.out.println("This coffee is great!")
NOTE:the case! Now here are my filenames (right click, properties):
TooColdException.java TooHotException.java
They are the same!
And here is TooHotException:
// In file except/ex6/TooColdException.java class TooHotException extends TemperatureException { public TooHotException(int temperature) { super(temperature); } }