| Author |
Package Error
|
Saravanan Jothimani
Greenhorn
Joined: Feb 25, 2005
Posts: 26
|
|
I created a package called dbconnection and I created java file called dbconn.java inside. My folder architecture is d:\soft\client\dbconnection I Created a userlogin.java in d:\ and imported the package as import soft.client.dbconnection.*; . When compiling UserLogin.java I dont get any error, But when I run UserLogin.java code I am getting an error as NoClassDefFoundError : /UserLogin. Pls guide me in this issue. Thanks in Advance. Saravanan.
|
 |
Vinay HS
Greenhorn
Joined: Feb 25, 2005
Posts: 5
|
|
|
Saravanan, Have you compiled the dbconn.java file and created its dbconn.class file. If not you must do that first, otherwise ur runtime will not be able to load the dbconn class and the exception would is raised.
|
 |
Saravanan Jothimani
Greenhorn
Joined: Feb 25, 2005
Posts: 26
|
|
Hi Vinay, I compiled dbconn.java and created the class file. But still I am getting the error. Thanks in Advance Saravanan
|
 |
Vinay HS
Greenhorn
Joined: Feb 25, 2005
Posts: 5
|
|
hi Saravanan, I think you have to make an entry in the CLASSPATH variable for your D:\. This should solve it.
|
 |
Saravanan Jothimani
Greenhorn
Joined: Feb 25, 2005
Posts: 26
|
|
Hi Vinay, This is my batch file for path. SET PATH=%PATH%;.;C:\j2sdk1.4.2_07\BIN; SET CLASSPATH=%CLASSPATH%;.;C:\j2sdk1.4.2_07\BIN; Thanks in Advance Saravanan
|
 |
Carol Enderlin
drifter
Ranch Hand
Joined: Oct 10, 2000
Posts: 1348
|
|
since . is in your classpath, are running from d:\ directory or somewhere else? Maybe you could confirm your classpath by running "set classpath" and checking the output. e.g.: C:\_Work\java>set classpath ClassPath=. [ February 25, 2005: Message edited by: Carol Enderlin ]
|
 |
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
|
|
Can you post the exact commands you type on the command line along with the output the make? You should be able to copy and paste directly from the DOS console window. Be sure to remove all .class files from previous atempts so we can see how it works when you do it from scratch. Also, as a side note, CLASSPATH should not include C:\j2sdk1.4.2_07\BIN. You can safely remove this path from your CLASSPATH variable. Layne
|
Java API Documentation
The Java Tutorial
|
 |
Saravanan Jothimani
Greenhorn
Joined: Feb 25, 2005
Posts: 26
|
|
Hi, I am writing dbconn.java program package soft.client.dbconnection; import java.sql.*; public class dbconn { public static void getConn() { Connection con = null; Statement sts = null; ResultSet rs = null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("Jdbc dbc:rgndsn"); sts = con.createStatement(); rs = sts.executeQuery("Select * from rgntable;"); } catch(ClassNotFoundException cnfe) { System.out.println("ClassNotFoundException " + cnfe.getMessage()); } catch (SQLException sqle) { System.out.println("Sql Exception " + sqle.getMessage()); } } } I dont get any error when I compile When I run the dbconn.java program I get this error Exception in thread "main" java.lang.NoClassDefFoundError: dbconn (wrong name: soft/client/dbconnection/dbconn) at java.lang.ClassLoader.defineClass0(Native Method) 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$100(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) at java.lang.ClassLoader.loadClassInternal(Unknown Source) When I compile UserLogin.java from D:\ UserLogin.java:2: package soft.client.dbconnection does not exist import soft.client.dbconnection.*; ^ UserLogin.java:9: cannot resolve symbol symbol : class dbconn location: class UserLogin dbconn db = new dbconn(); ^ UserLogin.java:9: cannot resolve symbol symbol : class dbconn location: class UserLogin dbconn db = new dbconn(); Thanks in Advance Saravanan
|
 |
 |
|
|
subject: Package Error
|
|
|