Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners null pointer error
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


akshat agnihotri
null pointer error
0 Answer(s)      3 years and 4 months ago
Posted in : Java Beginners


Respected sir there is a problem in this code when i add any new record in ms access data base from my code, it gives only null pointer error sir please help me my code are given below compilatation class name is "jd".

import java.io.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.sql.*;
import java.lang.String.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
class menu extends Frame implements ActionListener  
   {

Font m=new Font("monotype corsiva",Font.BOLD+Font.ITALIC,50);
Font m1=new Font("scriptmtbold",Font.BOLD+Font.ITALIC,40);
Font m2=new Font("scriptmtbold",Font.BOLD,20);
Frame f;
Label l1, l2,l3,l4,l5,l6,l7,l8,l9,l10;
Panel p;
Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10;
public menu()
{
super("INDANE - SHANTI GAS AGENCY");
int a=getWidth();
int b=getHeight();
setSize(a,b);
setBackground(Color.green);
setForeground(Color.blue);
p =new Panel();
setVisible(true);
p.setSize(400,300);
p.setBackground(Color.red);
setLayout(null);
l1=new Label("SHANTI GAS SERVICE");
l2=new Label("We Gives 18 Hours Service");
l3=new Label("Customer Care Application.");
l4=new Label("Add New Customer");
l5=new Label("Display Customer Record");
l6=new Label("Delete Cuctomer Record");
l7=new Label("Update Customer Record");
l8=new Label("Inquiary");
l9=new Label("Center Facility");
l10=new Label("We are happy to help you");
b4=new Button("ADD");
b5=new Button("Display");
b6=new Button("Delete Record");
b7=new Button("Update");
b8=new Button("Query");
b9=new Button("Facility List");

b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b4.setBounds(500,260,100,30);
b5.setBounds(500,300,100,30);
b6.setBounds(500,340,100,30);
b7.setBounds(500,380,100,30);
b8.setBounds(500,420,100,30);
b9.setBounds(500,460,100,30);
p.setBounds(a/20,b/20,700,70);
l1.setFont(m);
l2.setFont(m1);
l3.setFont(m2);
l4.setFont(m2);
l5.setFont(m2);
l6.setFont(m2);
l7.setFont(m2);
l8.setFont(m2);
l9.setFont(m2);
l10.setFont(m);
p.setBounds(50,50,700,80);
l2.setBounds(90,150,550,30);
l3.setBounds(90,190,550,30);
l4.setBounds(150,260,550,30);
l5.setBounds(150,300,550,30);
l6.setBounds(150,340,550,30);
l7.setBounds(150,380,550,30);
l8.setBounds(150,420,550,30);
l9.setBounds(150,460,550,30);
l10.setBounds(250,550,600,50);
p.add(l1);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
add(b9);
add(p);
add(l2);
add(l3);
add(l4);
add(l5);
add(l6);
add(l7);
add(l8);
add(l9);
add(l10);
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
}
public void processWindowEvent(WindowEvent w)
{
if(w.getID()==WindowEvent.WINDOW_CLOSING)
{
dispose();
System.exit(0);
}
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==b4)
{
addform f1=new addform();
f1.setVisible(true);    
}
}

}







class addform extends Frame implements ActionListener   
   {

Font m=new Font("monotype corsiva",Font.BOLD+Font.ITALIC,50);
Font m1=new Font("scriptmtbold",Font.BOLD+Font.ITALIC,30);
Font m2=new Font("scriptmtbold",Font.BOLD,25);
Font m3=new Font("scriptmtbold",Font.BOLD,18);
TextField t1,t2,t3,t4,t5,t6,t7,t8,t9;
Choice c1,c2,c3,c4;

Button b1;
Frame f;
Label l1,l2,l3,l4,l5,l6,l7,l8,l9,l10;
Panel p;


public addform()
{
super("INDANE - SHANTI GAS AGENCY");
setSize(950,950);
int a=getWidth();
int b=getHeight();

setSize(a,b);
setVisible(true);
setBackground(Color.green);
setForeground(Color.blue);
p=new Panel();
setLayout(null);

l1=new Label("Customer Detail Form");
l2=new Label("Customer Name");
l3=new Label("Father Name");
l4=new Label("HouseNo");
l5=new Label("Locality");
l6=new Label("City");
l7=new Label("State");
l8=new Label("Unit in Family");
l9=new Label("Cylendor Unit");
l10=new Label("Customer Code");
t1=new TextField(50);
t2=new TextField(50);
t3=new TextField(30);
t4=new TextField(30);
t5=new TextField(10);
c1=new Choice();
c2=new Choice();
c3=new Choice();
c4=new Choice();

c1.add("kanpur");
c1.add("Lucknow");
c1.add("Mumbai");
c2.add("Uttar Pradesh");
c2.add("Madhya Pradesh");
c3.add("1");
c3.add("2");
c3.add("3");
c4.add("Single");
c4.add("Double");
c4.add("Triple");
l1.setFont(m);
l2.setFont(m3);
l3.setFont(m3);
l4.setFont(m3);
l5.setFont(m3);
l6.setFont(m3);
l7.setFont(m3);
l8.setFont(m3);
l9.setFont(m3);
l10.setFont(m3);
b1=new Button("ADD RECORD");
b1.addActionListener(this);
p.setBounds(a/20,b/20,550,70);
l2.setBounds(50,200,150,20);
l3.setBounds(50,250,150,20);
l4.setBounds(50,300,150,20);
l5.setBounds(50,350,150,20);
l6.setBounds(50,400,150,20);
l7.setBounds(50,450,150,20);
l8.setBounds(50,500,150,20);
l9.setBounds(50,550,150,20);
l10.setBounds(50,600,160,20);
t1.setBounds(400,200,250,25);
t2.setBounds(400,250,250,25);
t3.setBounds(400,300,250,25);
t4.setBounds(400,350,250,25);
t5.setBounds(400,600,250,25);
b1.setBounds(300,700,250,25);
c1.setBounds(400,400,200,25);
c2.setBounds(400,450,200,25);
c3.setBounds(400,500,200,25);
c4.setBounds(400,550,200,25);
p.setBackground(Color.red);

p.add(l1);
add(p);
add(l2);
add(l3);
add(l4);
add(l5);
add(l6);
add(l7);
add(l8);
add(l9);
add(l10);
add(t1);
add(t2);
add(t3);
add(t4);
add(t5);
add(b1);
add(c1);
add(c2);
add(c3);
add(c4);
enableEvents(AWTEvent.WINDOW_EVENT_MASK);

}
public void processWindowEvent(WindowEvent w)
{
if(w.getID()==WindowEvent.WINDOW_CLOSING)
{
dispose();

}

}                          
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
try{


String nm,fnm,loclt,ct,st,cu;
int hn,uf,cc;
nm=new String(t1.getText());
fnm=new String(t2.getText());
 hn= Integer.parseInt(t3.getText());
loclt=new String(t4.getText());
ct=new String(t5.getText());
st=new String(t6.getText());
uf=Integer.parseInt(t7.getText());
cu=new String(t8.getText());
cc= Integer.parseInt(t9.getText());
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:project");

PreparedStatement stmt=cn.prepareStatement("insert into customerrecord values(?,?,?,?,?,?,?,?,?)");

stmt.setString(1,nm);
stmt.setString(2,fnm);
stmt.setInt(3,hn);
stmt.setString(4,loclt);
stmt.setString(5,ct);
stmt.setString(6,st);
stmt.setInt(7,uf);
stmt.setString(8,cu);
stmt.setInt(9,cc);
int rs=stmt.executeUpdate();
//cn.commit();
cn.close();
}
catch(SQLException c)
{} 
catch(Exception c)
{
System.out.println("error" +c);
}
}
}
}



class jd
{
 public static void main(String args[])
{
menu m=new menu();
}
}

Advertisement
View Answers

Related Tutorials/Questions & Answers:
null pointer error
null pointer error  Respected sir there is a problem in this code when i add any new record in ms access data base from my code, it gives only null pointer error sir please help me my code are given below compilatation class
null pointer error
null pointer error  Respected sir there is a problem in this code when i add any new record in ms access data base from my code, it gives only null pointer error sir please help me my code are given below compilatation class
Advertisements
Null pointer exception error in Jsp - JSP-Servlet
Null pointer exception error in Jsp  Hi i write a login page. when i validate the login value then the nullpointer exception error is occured. my..." attributes in the input tag So id,userpwd gives null pointer exception
Null pointer exception error in Jsp - JSP-Servlet
Null pointer exception error in Jsp  Expert:Majid Hi i write a login page. when i validate the login value then the nullpointer exception error..." attributes in the input tag So id,userpwd gives null pointer exception. Thanks
null pointer
null pointer  dear sir , what is mean by null pointer in c
Null pointer execption
Null pointer execption  what is null pointer exception. I am getting the null pointer exception in this line conn= com.mypay.dao.Connection.getConnection(); what is wrong
Null pointer execption
Null pointer execption  what is null pointer exception. I am getting the null pointer exception in this line conn= com.mypay.dao.Connection.getConnection(); what is wrong
null pointer exception in java
null pointer exception in java  What is null pointer exception in Java and when it occurs? Show it with an example.Thanks!   Java Null Pointer Exception
Httpservletresponse null pointer exception.
Httpservletresponse null pointer exception.  What is Httpservletresponse null pointer exception?   NullPointerException occurs when we try to implement an application without referencing the object and allocating
Null Pointer Exception
Null Pointer Exception  whis is the Null Pointer Exception in java? or define Null Pointer Exception with exp?   NullPointerException occurs, when you try to implement an application without referencing the object
NULL POINTER EXCEPTION
NULL POINTER EXCEPTION    What is the Root cause for Class caste exception in struts frame work .and how 2 handle that 1 please help me
Null Pointer Exception
Null Pointer Exception        Null pointer exceptions are the most common run time .... Normally, the latter one is more common. Rule for Debugging Null Pointer
Java null pointer exception
Java null pointer exception  Hi I've made an array of Book objects...]!=null){ if(strfield.contains(param)){ result+=library[counter...; Ah I just figured out my error, sorry guys. What a simple mistake, I feel
null pointer exception in jsp
null pointer exception in jsp  index.html <html> <body> <table align=center> <form action="Login.jsp" method="get">... getting **java.lang.NullPointerException** error , please see and resolve
pointer error java
pointer error java  How to catch null pointer errors in java if the if(value != null) or null
NUll POINTER EXCEPTION
NUll POINTER EXCEPTION  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException... of code i m getting null pointer Exception. can some one please explain what
null pointer exceptions
null pointer exceptions  import java.util.*; public class employee { static int ch; static int emp[]; String name; int id,age; float sal; void insert() { employee[] emp=new employee[90]; Scanner r
what is a null pointer exception in java
what is a null pointer exception in java  what is a null pointer exception in java
Null Pointer Exception - Java Beginners
Null Pointer Exception  How Can I Handle NullPoiniterException without using try/catch mechanism
Null pointer exception in hibernate - Hibernate
Null pointer exception in hibernate  Hi i am getting null pointer exception.while running the program in hibernate... is compiled successfully but while running the program i am getting null ponter
Java null pointer exception handling
Java null pointer exception handling   What... of modifying null value or obtaing a null value in an arrray. To handle null pointer... program? Is this extends from exception class of Java?   Java null
null pointer exception cannot be removed
null pointer exception cannot be removed  class list { public... Exception nothing; public int r; public list() { this(null,null,0); } public list(String e,int i) { this.elem = e; this.next = null
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Handle Null Pointer Exception while text file upload
Handle Null Pointer Exception while text file upload  I want the code for handling null pointer exception in jsp page. That is I need an error page for null pointer exception. The cause for null pointer exception is while
Why the null Pointer exception is comming? - Java Beginners
Why the null Pointer exception is comming?  My code is given below...")); String []oldOne = null; String[]newOne; int i = 0...}; String line; String line1; String[] tokens = null
when do we get null pointer exception in java
when do we get null pointer exception in java  can anybody explain me abt null pointer exception? like in wt situation do v get NPE? Are these 2 strings same? String str; String str=null
Clicking F5 and reentering value throws Null pointer exception
Clicking F5 and reentering value throws Null pointer exception  Hi, My page performs search operation.Normally when i enter a value and click... refresh my page and enter any value it is throwing Null pointer exception.can
Error in checking null value in string
Error in checking null value in string  Error in checking null value... in the following code: String registerno=null; registerno=request.getParameter("registerno"); int r=0; if(!registerno.equals(null)) /* Error line */ { r=1; } Can
 

 

 

DMCA.com