btnLogin.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
// validation of login panel
if(txtUser.getText().equalsIgnoreCase("") && txtPassword.getText().equalsIgnoreCase(""))
{
//JOptionPane.showMessageDialog(null, "in");
lblErrUser.setVisible(true);
lblErrPassword.setVisible(true);
}
else if (txtUser.getText().equalsIgnoreCase("") || txtPassword.getText().equalsIgnoreCase(""))
{
if(txtUser.getText().equalsIgnoreCase(""))
lblErrUser.setVisible(true);
else
lblErrPassword.setVisible(true);
}
else
{
// checking with database the credentials
try {
System.out.println(txtUser.getText().toString() + " : " + txtPassword.getText().toString());
resultuser = qp.checkUser(txtUser.getText().toString(),txtPassword.getText().toString());
if(resultuser == 0)
{
JFrame newFrame = new homeScreen();
newFrame.setVisible(true);
newFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
else
JOptionPane.showMessageDialog(null, "Wrong Credentials !!!");
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("ERROR n login panel");
}
}
}
});
qp is an object to class queryprocessing, pls fing below code:
public class queryProcessing {
Statement stmt = null;
ResultSet rs = null;
Connection con = null;
public queryProcessing() {
// TODO Auto-generated constructor stub
}
public int checkUser(String user, String pswd)
{
System.out.print("In checking");
String userdb = null;
String pswddb = null;
// TODO Auto-generated method stub
String sql = ("SELECT * FROM login");
try {
stmt = (Statement) con.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next())
{
userdb = rs.getString("user");
pswddb = rs.getString("password");
System.out.print(userdb + " : " + pswddb);
if(userdb.equalsIgnoreCase(user) && pswddb.equalsIgnoreCase(pswd))
return 0;
else
return 1;
}
}
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 1;
}
return 1;
}}
ERROR:
a : a
java.lang.NullPointerException
ERROR n login panel
at loginPanel$2.actionPerformed(loginPanel.java:115)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$300(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
spend two days on this error. I just want to get return value for the below line where qp is an object of other class file refering to the method returning some value to a variable in another class file. But i am getting above error, no matter what datatype i change.
Pls help ???
resultuser = qp.checkUser(txtUser.getText().toString(),txtPassword.getText().toString());