Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError

 
Geeta Ravikanti
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
My program is



package org.common;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MyUtility {
public static Connection getConnection(){
Connection conn = null;
String url = "jdbcracle:thin:@localhost:1521/";
String dbName = "xe";
String driver = "oracle.jdbc.driver.OracleDriver";
String userName = "SYSTEM";
String password = "remora";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
}catch(Exception ex){
ex.printStackTrace();
}
return conn;
}
public static void closeConnection(Connection con){
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}



after exectuion of the above program i am gettign the following errors

Exception in thread "main" java.lang.NoClassDefFoundError: MyUtility (wrong name
: org/common/MyUtility)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
4)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
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:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)


i set the calss path for ojdbc14.jar in appropriate path
Can any one tell me where did i mistaked

Regards
Geeta
 
Laxmikant Ruikar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per you error stack trace, you are not giving fully resolved name of your MyUtlilty class while compiling the code.

Or check path from where are you compiling code.

Specify your command to compile code.


LDR
 
Rajah Nagur
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something wrong with your PATH & CLASSPATH settings.

It seems that might have duplicate copies of MyUtility class, Delete or clean your system of duplicate copies of MyUtility class.
 
Geeta Ravikanti
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\Finance\WEB-
INF\c
lasses\org\common>javac MyUtility.java


C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\Finance\WEB-INF\c
lasses\org\common>java MyUtility


I am getting the error while running the appliation

I executed the program liket this

C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\Finance\WEB-INF\c
lasses\org\common>set CLASSPATH=ojdbc14.jar;.

Is there any wrong thing i did
plaese tell me the way of path getting right solution
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic