*
The moose likes Beginning Java and the fly likes Not able to execute after sucessfull compilation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Not able to execute after sucessfull compilation" Watch "Not able to execute after sucessfull compilation" New topic
Author

Not able to execute after sucessfull compilation

nitude gupta
Ranch Hand

Joined: Sep 04, 2008
Posts: 34
Hi All,
I m getting this exception when I m trying to execute my java program
Exception in thread "main" java.lang.NoClassDefFoundError: Test (wrong name: Java/Te
st_java/Test)
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: Test. Program will exit.

The problem is not with classpath I suppose as i am able to run a simple "Hello world" program...
any help on this....
TIA...
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

1.your Test class contain main method?
2. do you try to run the Test class with proper package name? example: java com.Test
Anupam Jain
Ranch Hand

Joined: Mar 16, 2010
Posts: 61

Seetharaman Venkatasamy wrote:1.your Test class contain main method?
2. do you try to run the Test class with proper package name? example: java com.Test


Yeah
These two checks should solve your problem...
If not... please put here your code and the commands of how you are running it...


SCJP-6.0 OCPJWCD-5.0
nitude gupta
Ranch Hand

Joined: Sep 04, 2008
Posts: 34
DBConnection.java
This file is defined @ E:\Java\Test_java


Test.java
This file is defined @ E:\Java\Test_java



and I have defined connection.properties @ pkg "E:\Java\Test_java\properties"
I am compiling it using
E:\Java\Test_java>javac *.java

for executing this I am using

E:\Java\Test_java>java Java.Test_java.Test

and getting this err:

Exception in thread "main" java.lang.NoClassDefFoundError: Java/Test_java/Test
Caused by: java.lang.ClassNotFoundException: Java.Test_java.Test
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: Java.Test_java.Test. Program will exit.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575


The problem is here . execute the class file from outside the package. i.e from E directory itself.


by the way: Please have a look at Java naming conventions
Anupam Jain
Ranch Hand

Joined: Mar 16, 2010
Posts: 61

Seetharaman Venkatasamy wrote:
The problem is here . execute the class file from outside the package. i.e from E directory itself.


by the way: Please have a look at Java naming conventions



correct solution... and yeah... a good look at the Java naming conventions is defibnitly required.

Also,
If there is some moderator listening right now... please delete one of my previous posts...
it got replicated because there was some network problem while I was posting it. I apologise for this...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37940
    
  22
Anupam Jain wrote:. . . If there is some moderator listening right now... please delete one of my previous posts...
it got replicated because there was some network problem while I was posting it. I apologise for this...
Done
Anupam Jain
Ranch Hand

Joined: Mar 16, 2010
Posts: 61

Campbell Ritchie wrote:
Anupam Jain wrote:. . . If there is some moderator listening right now... please delete one of my previous posts...
it got replicated because there was some network problem while I was posting it. I apologise for this...
Done



thanks Ritchie..
That was really lightning quick...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37940
    
  22
You're welcome
 
Don't get me started about those stupid light bulbs.
 
subject: Not able to execute after sucessfull compilation
 
Similar Threads
Exception in thread "main"
NoClassDefFoundError in a simple program
NoClassDefFoundError
NoClassDefFoundError in a simple program
abstract class