aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Package Headache Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Package Headache" Watch "Package Headache" New topic
Author

Package Headache

Christian Garcia
Ranch Hand

Joined: Jan 29, 2002
Posts: 77
I'm studying for the SCJP programmer test and am having an issue with implementing a 'package statement'.
I have a package statement in my '.java' file which represents the path of the class file in underlying directory structure. The code should print out a single line of text. Instead, an error is thrown:
Exception in thread "main" java.lang.NoClassDefFoundError: Example1 (wrong name: com/christiangarcia/examples/Example1)
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)
Any idea what is going on here???
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
Can you post the source code for main, including the package statement? Also, what are your command line arguments for the java command? I want to see how you are setting your classpath.
Thanks!

Rob


Rob
SCJP 1.4
Christian Garcia
Ranch Hand

Joined: Jan 29, 2002
Posts: 77
Originally posted by Rob Ross:
Can you post the source code for main, including the package statement? Also, what are your command line arguments for the java command? I want to see how you are setting your classpath.
Thanks!

Rob


Rob,
Here's the code:
package com.christian.examples;
public class Example1
{
public static void main(String[] args)
{
System.out.println( "This should work!!!" );
}
}

My CLASSPATH is set as an environment variable and includes the generic root (".") and E:\com\christian\examples;
Thanks for your help.
satish limaye
Greenhorn

Joined: Jan 28, 2002
Posts: 4
Hi Christian
I was facing similar problems
Thing to remember is that packages memic directory structures
and when you run this file you should use the fully qualified name in your case :
at this dir : E:\com\christian\examples\
run this command :
java com.christian.examples.Example1
This should work
satish
Christian Garcia
Ranch Hand

Joined: Jan 29, 2002
Posts: 77
Originally posted by satish limaye:
Hi Christian
I was facing similar problems
Thing to remember is that packages memic directory structures
and when you run this file you should use the fully qualified name in your case :
at this dir : E:\com\christian\examples\
run this command :
java com.christian.examples.Example1
This should work
satish

Satish,
That did the trick. However, this is still somewhat confusing.
I was under the impression that having the path to the class file(s) listed in the CLASSPATH would provide sufficient information for the Runtime to locate and execute the particular '.class' file.
I had expected that when I typed "java Example1" at the command line that the Example1.class file would have been located via the entry in the CLASSPATH environment variable. At the very least, the root "." should have worked.
If you could provide any more info regarding this I'd appreciate it.
CG
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
doesnt the " . " (dot) mean current directory?
try setting your class path to e:\
i had the same problem and this did the trick.
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
actually as i understand this the compiler goes to the path defined in your classpath and from there it seeks the whole directory trail of your package.
so u need to define the starting point to the whole package name.
so if your package starts from
c:\my documents\
for example..
then define that directory to your path.
im not sure if this is the way it is meant to be but hey this is the thing that WORKS!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Package Headache