• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Packages

 
Vasiq Molvizadah
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote this simple program in a package and my directory structure is E:\Java\folder and my main class is inside folder package...the code of the program is



When I'm trying to run this program from the current directory as folder...it gives me NoClassDefFoundError....Any help guys.....
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, if it compiles, the underlying package/folder structure should be fine.

Are you trying to run your program from the 'folder' folder or from the project's root path?
 
Vasiq Molvizadah
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm running this class from the "folder" folder and even if I try to run it from Java folder which the parent directory of "folder"..it doesn't work...but there was no error while compiling....why at runtime..
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most likely you're specifying the classpath incorrectly. Without knowing how you're *actually* trying to run it, though, it's impossible to help.
 
Vasiq Molvizadah
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:Most likely you're specifying the classpath incorrectly. Without knowing how you're *actually* trying to run it, though, it's impossible to help.


My directory structure where I stored this program is
E:
|
----->Java
|
-------->folder
|
------>Package.java

and I'm running the program from the folder package....it compiles fine but at runtime it gives an NoClassDefFoundError....
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, can't you just post the exact command line you're using? We cannot possibly know what you're doing wrong unless you TellTheDetails.

That said, don't run it from the "folder" directory, but the one above it.
 
Vasiq Molvizadah
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:Again, can't you just post the exact command line you're using? We cannot possibly know what you're doing wrong unless you TellTheDetails.

That said, don't run it from the "folder" directory, but the one above it.


This is what I'm getting after I tried to run the program.
E:\Java\folder>java PackageTest
Exception in thread "main" java.lang.NoClassDefFoundError: PackageTest (wrong name: folder/PackageTest)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
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$000(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)
Could not find the main class: PackageTest. Program will exit.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you not see the second sentence in my response?

You still need to either specify the classpath (or, less preferentially, rely on the default, which I *think* is ".", hence why I told you to run it from a different directory).
 
Vasiq Molvizadah
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:Did you not see the second sentence in my response?

You still need to either specify the classpath (or, less preferentially, rely on the default, which I *think* is ".", hence why I told you to run it from a different directory).


It's working perfectly now..thanks a lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic