On Tue, 22 Sep 1998 14:16:39 -0700, William Tchen wrote:

>Thanks for your suggestion, but I think the CLASSPATH variable on my system
>is properly set (which includes
>swingall.jar), otherwise I can't compile a file that refer to Swing classes.
>My CLASSPATH is:
>
>CLASSPATH=.:/JAVA/jdk1.1.6/lib/classes.zip:/JAVA/swing-1.0.3/swingall.jar

I figured the classpath was correct given that it compiles...

> I include the example file that I want to compile here:
>
> package JFCBook.Chapter2;
>
>import com.sun.java.swing.*;
>
>public class BasicFrame {
>    public static void main(String[] args) {
>        JFrame f = new JFrame("Simple Frame");
>        f.setSize(250, 200);
>        f.setVisible(true);
>    }
>}
>
>When I compile this file, there is no error message. But when I run it using
>'java BasicFrame'
>it says 'Can't find class BasicFrame'. Have you ever experience this before?
>Thanks for time.

Well, the problem is that the class is not "BasicFrame" 
but "JFCBook.Chapter2.BasicFrame"

If you remove the package statement or if you use the full class name
when trying to run the class you will be fine.

The java command needs the full class name since ther is no "import"
for the class name used to run from the command line - import is only
a compile-time typing shortcut and not a run-time item.  Classes that
are not in a specific package are in the "outer" package - as in nothing
to prefix the name.


Michael Sinz -- Director of Research & Development, NextBus Inc.
mailto:[EMAIL PROTECTED] --------- http://www.nextbus.com
My place on the web ---> http://www.users.fast.net/~michael_sinz

Reply via email to