hi all,
i'm using the following code and i'm getting
exception in thread "main" java.lang.nullp ointerexception at the line which is in bold. help me to solve this problem
import java.applet.*;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.sql.*;
import java.awt.event. *;
import sun.jdbc.odbc.* ;
public class Customerdetails extends Frame implements ActionListener
{
TextField ccod,cname,add, phno,conp,email ,fax;
Label l1,l2,l3,l4,l5, l6,l7;
Button save,exit;
Connection con;
ResultSet rs;
Statement stmt;
String s1,s2,s3,s4,s5, s6,s7;
public Customerdetails ()
{
super("Customer Details");
setSize(800,800 );
setLayout(new GridLayout(7,2, 45,45));
l1=new Label("Customer code");
l2=new Label("CompanyN ame");
l3=new Label("Address" );
l4=new Label("PhoneNum ber");
l5=new Label("Contact person");
l6=new Label("EmailAdd ress");
l7=new Label("FaxNumbe r");
add(l1);
add(ccod);
add(l2);
add(cname);
add(l3);
add(add);
add(l4);
add(phno);
add(l5);
add(conp);
add(l6);
add(email);
add(l7);
add(fax);
save.addActionL istener(this);
exit.addActionL istener(this);
setVisible(true );
addWindowListen er(new WindowAdapter() {
public void WindowClosing(W indowEvent w) {System.exit(0) ;}});
}
public void actionPerformed (ActionEvent ae)
{
if(ae.getSource ()==save)
{
s1=ccod.getText ();
s2=cname.getTex t();
s3=add.getText( );
s4=phno.getText ();
s5=conp.getText ();
s6=email.getTex t();
s7=fax.getText( );
try
{
String query = "insert into Customerdetails (Customercode,C ompanyName,Addr ess,PhoneNumber ,Contact person,EmailAdd ress,FaxNumber) "+
"values('"+s1+" ','"+s2+"','"+s 3+"','"+s4+"',' "+s5+"','"+s6+" ','"+s7+"')";
Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
con=DriverManag er.getConnectio n("jdbc:odbc:pr ism");
stmt=con.create Statement();
rs=stmt.execute Query(query);
stmt.close();
}
catch(ClassNotF oundException e)
{
System.out.prin tln(e);
}
catch(SQLExcept ion e)
{
System.out.prin tln(e);
}
}
if(ae.getSource ()==exit)
{
System.exit(0);
}
}
public static void main(String args[])
{ Customerdetails cd=new Customerdetails ();
}
}
Sep 10 '07
18 2596
save is null at that point. - Button save = new Button("Save");
Here, save holds a reference to an instance of the Button class which is not null.
Hi,
Isn't it the duplicate post. I think there are two posts running parallely and both have same code and problem.
One (the?) Problem is somewhere else: -
super("SPlanting ");
-
setSize(800,800);
-
setLayout(new GridLayout(7,2,45,45));
-
l1=new Label("Date");
-
l2=new Label("Noofmixes");
-
l3=new Label("TotalBentomikused");
-
l4=new Label("TotalLusformused");
-
l5=new Label("starttime");
-
l6=new Label("Offtime");
-
l7=new Label("PowerConsumed");
-
l8=new Label("Opertorname");
-
-
-
add(l1);
-
add(date);
-
add(l2);
-
add(nom);
-
add(l3);
-
add(tb);
-
add(l4);
-
add(tl);
-
add(l5);
-
add(st);
-
add(l6);
-
add(ft);
-
add(l7);
-
add(pc);
-
add(l8);
-
add(on);
-
You never initialized "date".
Greetings,
Nepomuk
Much worse is - save.addActionListener(this);
-
exit.addActionListener(this);
Both save and exit are null at that point.
Hi,
Isn't it the duplicate post. I think there are two posts running parallely and both have same code and problem.
It is. I've closed the second one.
Nepomuk 3,112
Recognized Expert Specialist
Much worse is - save.addActionListener(this);
-
exit.addActionListener(this);
Both save and exit are null at that point.
Uff, I never even got that far. Pradeep84, have you worked through a few Java tutorials? Those errors make me suspect, that you haven't understood, how to create Objects in Java. Have a look at the Articles list.
Greetings,
Nepomuk
Hi...
i hav encoded these codes..in the program.. but it shows error in the main class of the program -
-
-
Button save= new Button("Save");
-
Button exit= new Button("Exit");
-
-
public static void main(String args[])
-
{
-
Customerdetails cud= new Customerdetails();}
-
Thanks
regards
pradeep
Nepomuk 3,112
Recognized Expert Specialist
Hi...
i hav encoded these codes..in the program.. but it shows error in the main class of the program -
-
-
Button save= new Button("Save");
-
Button exit= new Button("Exit");
-
-
public static void main(String args[])
-
{
-
Customerdetails cud= new Customerdetails();}
-
Thanks
regards
pradeep
Continue checking, if the Objects you're using have been initialized BEFORE use - otherwise you'll have errors when you try to initialize the Customerdetails object.
Greetings,
Nepomuk
Hi...
i hav encoded these codes..in the program.. but it shows error in the main class of the program -
-
-
Button save= new Button("Save");
-
Button exit= new Button("Exit");
-
-
public static void main(String args[])
-
{
-
Customerdetails cud= new Customerdetails();}
-
Thanks
regards
pradeep
Where did you put this code. Put the code that you now have.
Add =java to the opening code tag when you put your code in code tags
Thank u for the suggestion u made. i have solved my problem
Thanks a lot.....
Regards
Pradeep
Thank u for the suggestion u made. i have solved my problem
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Phillip Montgomery |
last post by:
Hello all;
I'm trying to debug an issue with a java script called, SelectSockets.
It appears to be a fairly common one found on the web. I downloaded
the SGI Java v1.4.1 installation from SGI's webpage and installed it
using SGI's swmgr application. The installation was very straight
forward and there were no errors when I installed the package.
Then I ran /usr/java2/bin/javac SelectSockets.java to make the
SelectSockets.class file.
|
by: Andy Howells |
last post by:
Can anybody help me on this? I am getting the below error but have not
got a clue why. The file in my classpath eing used has the class that
it says is not defined. Any ideas? I am running java version 1.4.0 and
WMQ Series version 5.3 with CSD04.
Exception in thread "main" java.lang.NoClassDefFoundError:
com/ibm/mq/server/MQSESSION
at com.ibm.mq.MQSESSIONServer.getMQSESSION(MQSESSIONServer.java:67)
at...
|
by: jith87 |
last post by:
What is ths error.????? I m nw loading the JDBC driver for connection with MySql.
Exception in thread "main" java.lang.NoClassDefFoundError: MySQLJDBCDriverTest
|
by: GHKASHYAP |
last post by:
Hi this is the exception i am getting when i am trying to run this application:
Exception in thread "main" java.lang.NullPointerException
thanks in advance..
package com.inventive.StockMarketTrading;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
|
by: Ananthu |
last post by:
Hi
This is my codings in order to access mysql database from java.
Codings:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
| |
by: tiyaramunna |
last post by:
I am trying to configure my system with Java program just to practice on the coding....when i compile a test.java program i am able to see the class file but i cant run the program ... I am getting the following error
Exception in thread "main" java.lang.NoClassDefFoundError: test
Caused by: java.lang.ClassNotFoundException: test
at java.net.URLClassLoader$1.run(Unknown Source)
at...
|
by: jmitch89 |
last post by:
I don't why I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError
The statement below works just fine:
java -cp "appframework-1.0.3.jar;swing-worker-1.1.jar";CurrentStrobe.jar com.visionpro.currentstrobe.CurrentStrobeApp
However, the statement below produces the error:
java -cp "appframework-1.0.3.jar;swing-worker-1.1.jar" -jar CurrentStrobe.jar
Exception in thread "main"...
|
by: jimgym1989 |
last post by:
I dont get it..why is the error: Exception in thread "main" java.util.InputMismatchException
this is my code
/**
* @(#)textFileRead.java
*
*
* @author
* @version 1.00 2008/10/17
*/
|
by: ohadr |
last post by:
hi,
i get Exception in thread "main" java.lang.NullPointerException
when i run my application.
the exact error is:
"Exception in thread "main" java.lang.NullPointerException
at sortmergejoin.MergeJoin.Field(MergeJoin.java:204)
at sortmergejoin.MergeJoin.SMJoin(MergeJoin.java:84)
at sortmergejoin.MergeJoin.<init>(MergeJoin.java:34)
at sortmergejoin.Main.main(Main.java:24)
Java Result: 1"
|
by: onlinegear |
last post by:
HI i am writing this for college i know i have loads of combo boxes with nothing in the i havent got that far yet. but every time i run this is comes up with this erro
run:
Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1041)
at java.awt.Container.add(Container.java:365)
at orderingsystem.OrderingSystem.<init>(OrderingSystem.java:261)
at...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |