The Artima Developer Community
Sponsored Link

Java Answers Forum
Objects Seminar: Exceptions, problem runnng code

3 replies on 1 page. Most recent reply: Aug 11, 2007 5:17 AM by Murray Davis

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Murray Davis

Posts: 3
Nickname: mgdjava52
Registered: Aug, 2007

Objects Seminar: Exceptions, problem runnng code Posted: Aug 5, 2007 5:04 PM
Reply to this message Reply
Advertisement
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?


Murray Davis

Posts: 3
Nickname: mgdjava52
Registered: Aug, 2007

Re: Objects Seminar: Exceptions, problem runnng code Posted: Aug 5, 2007 5:12 PM
Reply to this message Reply
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.

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: Objects Seminar: Exceptions, problem runnng code Posted: Aug 10, 2007 11:17 PM
Reply to this message Reply
> 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.

Murray Davis

Posts: 3
Nickname: mgdjava52
Registered: Aug, 2007

Re: Objects Seminar: Exceptions, problem runnng code Posted: Aug 11, 2007 5:17 AM
Reply to this message Reply
I don't think that is the problem.

Here are the error messages:

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);
}
}

Flat View: This topic has 3 replies on 1 page
Topic: Objects Seminar: Exceptions, problem runnng code Previous Topic   Next Topic Topic: Question/Answer Changing Background Colors

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use