• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
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
 
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • 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).

 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic