Forums Register Login

Not able to execute after sucessfull compilation

+Pie Number of slices to send: Send
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...
1
+Pie Number of slices to send: Send
1.your Test class contain main method?
2. do you try to run the Test class with proper package name? example: java com.Test
+Pie Number of slices to send: Send
 

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...
+Pie Number of slices to send: Send
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.
1
+Pie Number of slices to send: Send

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
+Pie Number of slices to send: Send
 

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...
1
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
 

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...
+Pie Number of slices to send: Send
You're welcome
It's weird that we cook bacon and bake cookies. Eat this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 953 times.
Similar Threads
NoClassDefFoundError
abstract class
NoClassDefFoundError in a simple program
NoClassDefFoundError in a simple program
Exception in thread "main"
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 02:07:59.