hi,i m getting the following excption,though i hv properly set the classpath ,,,

i m able to rum other programs,,,,

plz help,,,

Exception in thread "main" java.lang.NoClassDefFoundError: admins (wrong name: a
dmins/admins)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
1)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: admins.  Program will exit.
package admins;

import java.awt.*; 

import java.awt.event.*; 

import javax.swing.*;

import java.sql.*;

public class admins implements ActionListener 
{
	private static String Insert = "Insert";

	private static String Delete = "Delete";

	private static String Update = "Update";

	private static String Show = "Show";

	Container cnt=getContentPane();



	JButton btninsert =new JButton("Insert");

	JButton btndelete =new JButton("Delete");

	JButton btnupdate =new JButton("Update");

	JButton btnshow =new JButton("Show");

	


	JButton insert =new JButton("Insert");

	JButton delete =new JButton("Delete");

	JButton update =new JButton("Update");

	JButton show =new JButton("Show");

		

	JLabel lblno=new JLabel("Question No.");

	JLabel lblque=new JLabel("Question");

	JLabel lblop1=new JLabel("Option 1 :");

	JLabel lblop2=new JLabel("Option 2 :");

	JLabel lblop3=new JLabel("Option 3 :");

	JLabel lblop4=new JLabel("Option 4 :");

	JLabel lblcorect=new JLabel("Correct Option :");


	JTextField txtno= new JTextField();	

	JTextField txtque= new JTextField();

	JTextField txtop1= new JTextField();
	
	JTextField txtop2= new JTextField();
	
	JTextField txtop3= new JTextField();
	
	JTextField txtop4= new JTextField();

	JTextField txtcorect= new JTextField();



	public JPanel p1 = new JPanel();

	public JPanel p2 = new JPanel();


	admins()
	{
	

		p1.setLayout(null);

		p2.setLayout(null);

		p1.add(btninsert);

		p1.add(btndelete);

		p1.add(btnshow);

		p1.add(btnupdate);


		p2.add(insert);

		p2.add(lblno);
		
		p2.add(lblque);

		p2.add(lblop1);

		p2.add(lblop2);

		p2.add(lblop3);

		p2.add(lblop4);

		p2.add(lblcorect);

		p2.add(txtno);

		p2.add(txtque);

		p2.add(txtop1);

		p2.add(txtop2);

		p2.add(txtop3);

		p2.add(txtop4);

		p2.add(txtcorect);


		btninsert.setBounds(10,50,90,25);

		btnupdate.setBounds(10,115,90,25);

		btndelete.setBounds(10,180,90,25);

		btnshow.setBounds(10,245,90,25);

		


		lblno.setBounds(150,45,20,10);

		lblque.setBounds(150,50,280,25);

		lblop1.setBounds(150,135,280,25);

		lblop2.setBounds(150,200,280,25);

		lblop3.setBounds(150,265,280,25);

		lblop4.setBounds(150,325,280,25);

		lblcorect.setBounds(150,390,280,25);


		txtno.setBounds(320,45,20,10);

		txtque.setBounds(320,50,280,45);

		txtop1.setBounds(320,135,280,25);

		txtop2.setBounds(320,200,280,25);

		txtop3.setBounds(320,265,280,25);

		txtop4.setBounds(320,325,280,25);

		txtcorect.setBounds(320,390,280,25);



		insert.setBounds(125,455,90,25);

		


		btninsert.addActionListener(this);
		
		btndelete.addActionListener(this);

		btnupdate.addActionListener(this);

		btnshow.addActionListener(this);

		btninsert.setActionCommand(Insert);

		btndelete.setActionCommand(Delete);

		btnupdate.setActionCommand(Update);

		btnshow.setActionCommand(Show);



		
		CustomPanel panel = new CustomPanel();

		p1.add(panel);



	
		Color lemon=new Color( 255,246,143);
	          
		p1.setBackground(lemon);

		p2.setBackground(lemon);

		p2.setVisible(false);

		
		

	}
	class CustomPanel extends JPanel
	{   

		public void paintComponent (Graphics painter)   
		{    
			
			Image pic =Toolkit.getDefaultToolkit().getImage("admin.bmp");

			if(pic != null) 

			painter.drawImage(pic, 115, 50, this);    

		}

	}
	



	public void actionPerformed(ActionEvent e) 
	{	 
		String cmd = e.getActionCommand();

		if (Insert.equals(cmd)) 
		{

			p2.setVisible(true);


			if (e.getSource() == insert)
			{

				int qno = Integer.parseInt(txtno.getText());

				String que=txtque.getText();

				String op1=txtop1.getText();

				String op2=txtop2.getText();

				String op3=txtop3.getText();

				String op4=txtop4.getText();

				int corect=Integer.parseInt(txtcorect.getText());

				
				
			
				try
				{
					Class.forName("oracle.jdbc.driver.OracleDriver");

					String url="jdbc:oracle:thin:@localhost:1521:xe";

					String username="hr";

					String password="hr";

					Connection connection=DriverManager.getConnection(url,username,password);

					Statement statement=connection.createStatement();
        					
			 		String query="Insert into test values("+qno+",'" +que+"','" +op1+ "','" +op2+ "','" +op3+ " ','" +op4+ "',"+corect;

					ResultSet resultset=statement.executeQuery(query);

					JOptionPane.showMessageDialog(insert,"Question insert");

					connection.close();			
 				}
				catch(ClassNotFoundException cnfe)
				{
	
					System.out.print("ERROR LOADING DRIVER: " + cnfe);

				}			
				catch(SQLException se)
				{ 
					System.out.print("SQL Exception  " + se);

				}

			}


		}

	}


	public static void main(String args[])
	{
		admins ad=new admins();


		
	}
	
}

plz help me,,its urgent

Hi ,
I looked in your code.
y did you wrote class CustomPanel inside admins?
Please make sure where CustomPanel should be.
I think it should be outside of admins class.

One more question y did you keep your package name and class name same i.e. admins

If you have any doubt please let me know.

thanks.

What is the command line you are using to execute the program? What directory are you in when you execute that command.

You should be in the folder that contains the admins folder and the command should be:

java admins.admins

Because your class is in the package: admins

Hi ,
I looked in your code.
y did you wrote class CustomPanel inside admins?
Please make sure where CustomPanel should be.
I think it should be outside of admins class.

One more question y did you keep your package name and class name same i.e. admins

If you have any doubt please let me know.

thanks.

thnks

custom panel class i hv used to insert pic

i hv used it earlier also,,n i used it inside

package names is also not a problem ,,bcz i hv used it earlier like that ,,n it ws working fine

What is the command line you are using to execute the program? What directory are you in when you execute that command.

You should be in the folder that contains the admins folder and the command should be:

java admins.admins

Because your class is in the package: admins

i m using command prompt

javac admins.java

yes i m in that folder only,,login folder which contains admins folder

i tried using it without package

without package its working fine

plz help

i tried using it without package

without package its working fine

plz help

Try running it is

java -cp . admins.admins

'-cp', abbreviation for ClassPath tells the JVM where to look for your class files (or libraries or the top level package folder in this case)
The '.' after '-cp' tells it to look in the current directory, since you are running the program from the parent directory of 'admins'.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.