This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in thread "main" java.lang.NoClassDefFoundError: Voice1" Watch "Exception in thread "main" java.lang.NoClassDefFoundError: Voice1" New topic
Author

Exception in thread "main" java.lang.NoClassDefFoundError: Voice1

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Hi,

I have put my java source file inside /usr/java/jdk1.6.0_04/bin and compiled the program using javac Voice1.java.It gets compiled.
But when i tried to run the program using java Voice1,it displays the following error:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at Voice1.getMySqlConnection(Voice1.java:24)
at Voice1.run(Voice1.java:79)
at Voice1.main(Voice1.java:305)



Then i have added mysql connector.jar in the path /usr/java/jdk1.6.0_04/bin and then i tried to run the class as follows:


java -cp mysql-connector-java-3.0.17-ga-bin.jar Voice1


Now i am getting the following error:



Exception in thread "main" java.lang.NoClassDefFoundError: Voice1
Caused by: java.lang.ClassNotFoundException: Voice1
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)



what is the problem here? Any classpath issue?Please help me to solve this.

Thanks.
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
I have solved this problem .thanks
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3817

preethi Ayyappan wrote:I have put my java source file inside /usr/java/jdk1.6.0_04/bin and compiled the program using javac Voice1.java.


That's a very bad practise. Use your own working directory instead.


Then i have added mysql connector.jar in the path /usr/java/jdk1.6.0_04/bin and then i tried to run the class as follows:


bin directory is for executables, put the third party library files in separate place (should be in CLASSPATH).


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
 
Don't get me started about those stupid light bulbs.
 
subject: Exception in thread "main" java.lang.NoClassDefFoundError: Voice1
 
Similar Threads
package javax.servlet.http does not exist
Starting Websphere 6.0 in Eclipse3.3
is exist any multi record catalogue? or better to use DB? or array?
Exception in thread "main" java.lang.NoClassDefFoundError
Exception in thread "main" java.lang.NoClassDefFoundError