File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Can compile java code but not run (exception) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can compile java code but not run (exception)" Watch "Can compile java code but not run (exception)" New topic
Author

Can compile java code but not run (exception)

Daniel Lucas
Ranch Hand

Joined: Apr 24, 2006
Posts: 48
OK, this is the first program I've tried to run on my pc at home. I've gone through a year of programming at high school and learned very little, so I'm doing Head First Java on my own at home. At school I used TextPad to compile and run the code, which is what I'm doing at home for now (eventually I'll move on to use eclipse, methinks). Anyway, I installed the j2se Software Development Kit 1.5 (5.0) Update 6. I hate it how sun puts the Runtime Environment so close to the SDK... ugh! But anyway, I managed to avoid downloading the wrong one.

TextPad compiles the following code correctly:



But when I try to run I get this exception:
What's the problem? I read a previous thread with 30 posts about setting the PATH. Is that my problem here?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
No the PATH is not your problem, it's the CLASSPATH. You need to make sure that the .class file can be found in the CLASSPATH.
Daniel Lucas
Ranch Hand

Joined: Apr 24, 2006
Posts: 48
In my system variables I have a variable called CLASSPATH with the value "C:\Program Files\Java\jre1.5.0_06\lib\ext\QTJava.zip"

That's for the Java Runtime Environment. What do I need to do with the CLASSPATH to get the program to run properly?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
One way is to modify the System CLASSPATH and include . for the current directory.

Another option is to set the CLASSPATH on the command line.





You can include multiple directories in the CLASSPATH by seperating them with a semicolon.
Daniel Lucas
Ranch Hand

Joined: Apr 24, 2006
Posts: 48
NEVERMIND GUYS! I just got it to work. What's confusing is the installation instructions sun gives ( http://java.sun.com/j2se/1.5.0/install-windows.html ) does not mention the need to add both a PATH AND CLASSPATH to the User Variables. Now I can use TextPad just like at school!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

That's because normally you do not have to set the CLASSPATH environment variable. By default, if CLASSPATH isn't set, Java looks in the current directory for class files.

You have Apple QuickTime installed on your computer, which set the CLASSPATH variable. Now Java looks ONLY at the QuickTime ZIP file, because the current directory (".") isn't in your classpath.

So it's not Sun's fault, it's Apple's QuickTime that messed up your CLASSPATH setting.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Daniel Lucas
Ranch Hand

Joined: Apr 24, 2006
Posts: 48
I didn't realize that Quicktime did that until you just told me, Jesper Young. I guess it was luck that I managed to solve my problem (yes I did have Quicktime installed).

On the other hand, it is Sun's fault and it isn't Sun's fault that Quicktime screws up their SDK. It isn't Sun's fault because someone else's software conflicts with Sun's, while it is Sun's fault because they did not mention in the installation instructions that this is a common problem and how to fix it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can compile java code but not run (exception)
 
Similar Threads
first program, first error
just started
First dumb question
2 questions about classpath
Newbie: Run-time error