Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes Fun runtime issues! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Fun runtime issues!" Watch "Fun runtime issues!" New topic
Author

Fun runtime issues!

David Miranda
Ranch Hand

Joined: Mar 14, 2005
Posts: 34
Hi all,

I've developed some java code in the NetBeans IDE 4.1, it compiles and runs fine in NetBeans.

I want to try to run to same code via command line. I get this message:

Exception in thread "main" java.lang.NoClassDefFoundError: testproject/build/cla
sses/testproject/testprog (wrong name: testproject/testprog)
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)

Pretty common issue on these forums, so I researched what people did to fix them. I checked my class path variables (both user and system), they are both:
C:\Netbeans_projects\

The class file (testprog.class) is saved in this directory:
C:\NetBeans_projects\TestProject\build\classes\testproject\

I go to the c:\NetBeans_projects directory and type:
java testproject.build.classes.testproject.testprog

And I get the error above, I've also tried:
java testproject/build/classes/testproject/testprog
java testproject\build\classes\testproject\testprog

None of them work.

Also, I've tried to compile the java file (testprog.java), saved at:
C:\NetBeans_projects\TestProject\src\testproject\
via command-line. It works, but saves the .class file in the src directory instead of the build directory. (But thats a separate issue)

Any idea of what I'm forgetting?

Thanks
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
does your file has a package declaration?

if no, you cant type:
>java testproject\testprog, but just
>java testprog

BTW: use capital letter at begining of class name, like Testprog.java, or, for sake of readability, TestProg.java


java amateur
Arjun K
Ranch Hand

Joined: Mar 09, 2005
Posts: 39

Taken From : David Miranda
It works, but saves the .class file in the src directory instead of the build directory. (But thats a separate issue)


javac -d d:/projects/testproj/build testproject.java

This will save the class file in build directory.

Regards,
Arjun K.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Fun runtime issues!
 
Similar Threads
Issues with cmd java command
Exception in thread "main"
Test class cannot find other class
WAMP/Java/MysqlConnector Issue
what is the problem with this code