Hello everyone,
I have a really weird problem (or so it seems) with running Java programs that are part of packages:
Let's say a source file has the first line "package a.b.c;", and my classpath is set to ".;s:\classpath". The source file is "s:\classpath\a\b\c\Foo.java" and contains the public class "Foo", which in turn contains "main". I have added the JDK commands to the "Tools" menu, and compiling and running the program work like a charm.
Now, when I change the menu entry and select "Prompt for parameters", and simply hit <Return>, or if I use the MS DOS command line, change to "s:\classpath\a\b\c" and type "java Foo", I get the following error message from the Java interpreter (compiling works just fine, though, and the class exists as "Foo.class"
in "s:\classpath\a\b\c"!):
Exception in thread "main" java.lang.NoClassDefFoundError: Foo
(wrong name: a/b/c/Foo)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
This does *not* happen when I remove the package line from the source file.
I have the latest Java 2 version 1.3.1 SDK for Windows, Windows 98 SE and TextPad 4.4.2. The drive referred to by "s:" is a network drive on a samba server, running on a Linux box (latest 2.2.x kernel, latest samba release with all security patches). The *forward* slashes in the error message seem strange, but then again, why for heaven's sake does this work when using the Textpad menu entry, but *only* when *not* being prompted for parameters (even if I simply hit return, which should have same effect as not prompting for parameters in the first place)?
Ideas, anyone? (I guess this might not be a Textpad problem, but maybe one of you has run into this one, too.)
TIA,
Matt
Error executing Java programs
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
Re: Error executing Java programs
go to s:\classpath (instead of s:\classpath\a\b\c) and say
java a.b.c.Foo (instead of java Foo)
java a.b.c.Foo (instead of java Foo)
Re: Error executing Java programs
Andreas is right, you should go to S:\classpath and execute
java a.b.c.Foo
Regarding the remark above "(compiling works just fine, though, and the class exists as "Foo.class" in "s:\classpath\a\b\c"!)", well actually the package information is already embedded inside the .class file. It is not simply "deduced" from the directory structure in which it resides. Therefore, though the filename may be Foo.class, java (or appletviewer, or any other Java interpreter) will still recognize its name as a.b.c.Foo (no matter where it resides), and execute (or raise error) accordingly.
java a.b.c.Foo
Regarding the remark above "(compiling works just fine, though, and the class exists as "Foo.class" in "s:\classpath\a\b\c"!)", well actually the package information is already embedded inside the .class file. It is not simply "deduced" from the directory structure in which it resides. Therefore, though the filename may be Foo.class, java (or appletviewer, or any other Java interpreter) will still recognize its name as a.b.c.Foo (no matter where it resides), and execute (or raise error) accordingly.