Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have solved this problem .thanks
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic