Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can't run a class with a package statement added

 
david eberhardt
Ranch Hand
Posts: 158
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I compiled the following class ok but can't run it:

when I try to run it, I see:
C:\david1>java Child
Exception in thread "main" java.lang.NoClassDefFoundError: Child (wrong name: da
vid1/Child)
at java.lang.ClassLoader.defineClass0(Native Method)
...etc, etc ...
(note: if I comment out the package declaration, it compiles and runs fine)
my directory structure is
C:\david1
the .java and resulting 3 class files are all in this \david1 subdirectory
my autoexec.bat files contains:
SET BLASTER=A220 I5 D1 T4
CALL C:\PROGRA~1\PERSON~1\PCSVARS.BAT
SET PATH=.;C:\JDK1.3.1\BIN;C:\david1;C:\IBMVJava2\eab\bin;C:\WINDOWS;C:\WINDOWS\COMMAND;%PATH%;"C:\Program Files\Executive Software\DiskeeperWorkstation\"
IF EXIST C:\IMNNQ_95\IMNENV.BAT CALL C:\IMNNQ_95\IMNENV.BAT
SET CLASSPATH=.;C:\david1;C:\JDK1.3.1\BIN;C:\IBMVJava2\eab\runtime30;
SET IMNINSTSRV=C:\IMNNQ_95
MSCDEX /D:MSCD001 /V
doskey /insert /keysize:64
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,
1. make sure that your class is in a directory called "david1".
2. cd to the parent of that directory, so that running 'ls' or 'dir' will display the david1 directory.
3. type in javac david1/*.java
4. type in java david1.GrandParent
HTH,
M
 
david eberhardt
Ranch Hand
Posts: 158
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Max,
didn't work and I didn't really understand why it might have made it work.
the Java books I have don't explain this too well and I have many Java books!
I tried again with this:

I made a new directory C:\BIN
put "C:\BIN in my path and classpath using autoexec.bat file (verified changes using >set command)
put source in BIN and ran javac -d . Stinky.java
it compiled ok
tried to run >java Stinky from BIN, from C:, and from quirky subdirectories
every time I get an error that says "Exception in thread "main" java.lang.NoClassDefFoundError: Stinky (wrong name: quirky/Stinky)"
I also looked in the docs for answers under "\jdk1.3.1\docs\tooldocs\findingclasses.html" to no avail ...
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you know that you have to be religious in observing capitialization, right? I mean, directory names, command line arguments, file names, etc?
M
 
Chad McGowan
Ranch Hand
Posts: 265
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I made a new directory C:\BIN
put "C:\BIN in my path and classpath using autoexec.bat file (verified changes using >set command)
put source in BIN and ran javac -d . Stinky.java
it compiled ok
tried to run >java Stinky from BIN, from C:, and from quirky subdirectories
every time I get an error that says "Exception in thread "main" java.lang.NoClassDefFoundError: Stinky (wrong name: quirky/Stinky)"
I also looked in the docs for answers under "\jdk1.3.1\docs\tooldocs\findingclasses.html" to no avail ...[/QB]

try this from c:\bin directory
java quirky.Stinky
This should work for you. You always should invoke using the full package name.
Chad
 
david eberhardt
Ranch Hand
Posts: 158
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chad McGowan:

try this from c:\bin directory
java quirky.Stinky
This should work for you. You always should invoke using the full package name.
Chad

progress!!
ok - I had a directory C:\BIN which contained this source file:

then I ran a few commands:
C:\BIN>javac -d . Stinky2.java
C:\BIN>java quirky.Stinky2
I am Stinky class
this worked as Chad suggested !!!
then I tried without using the full package name.
C:\BIN>java Stinky2
Exception in thread "main"java.lang.NoClassDefFoundError: Stinky2
[b]thanks folks, esp Chad ... I will ponder some more from here !!!
[ July 16, 2002: Message edited by: david eberhardt ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic