Question:
ERROR:: java.lang.NullPointerException .. I need to solve this soon as i hv an assignment to complete.pl help?
Hesh
2013-01-25 02:54:30 UTC
After typing my program in Netbeans IDE 6.1 there wasn't any error in the code or even after running it.its a simple Inventory program.after running the program when click a button i get the above error... please help me to solve this.

this is what i typed

import java.sql.Connection;

import java.sql.DriverManager;
import java.sql.Statement;

public class Supplier extends javax.swing.JFrame {
private static Connection con;
public static Connection getMyConnection() throws Exception{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Inventory","root","1234");
return con;

}

public Supplier() {
initComponents();
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

try{
Class.forName("com.mysql.jdbc.Driver");
Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/Inventory","root","1234");
Statement s = con.createStatement();
s.executeUpdate("insert into Supplier Values('" +no.getText()+ "','" +Sname.getText()+ "','" +Saddress.getText()+ "')");

}
catch(Exception ex){
ex.printStackTrace();
}
}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

try{
Class.forName("com.mysql.jdbc.Driver");
Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/Inventory","root","1234");
Statement s = con.createStatement();
s.executeUpdate("DELETE FROM Supplier WHERE Sno='"+no.getText()+"',Name='"+Sname.getText()+"',Address='"+Saddress.getText()+"'");

}catch(Exception ex){
ex.printStackTrace();
}
}

public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Supplier().setVisible(true);
}
});
}
Three answers:
AnalProgrammer
2013-01-25 03:18:18 UTC
When you get the error there will be method names and line numbers where the error occurs. The first may just be a method call in the main method, but one of the lines will be the line that actually contains the error.



Have fun.
harry
2013-01-25 06:42:05 UTC
As said below,there will be line no in it. But in general,null pointer exception refers to some variables that were never declared in your program are used in it.The variable is not referenced that is not declared before being used.So check the line no.,see the variables used in it and their data types as well.It'll be better if u can specify which line there it shows the error.
2017-01-11 22:26:56 UTC
yet didnt u listen frank desirous to bypass lower back back to get his revenge and shot the polar bear. yet there became yet another tap on his shoulder. he unearths himself searching at 2 panda bears. properly u see pandas have this ingredient about threesomes


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...