• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Package Error

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Saravanan,

I think you have to make an entry in the CLASSPATH variable for your D:\. This should solve it.
 
Saravanan Jothimani
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saravanan Jothimani
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Paddy spent all of his days in the O'Furniture back yard with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic