I wrote a code linking my sql database with project. I have been attempting to create an ATM with graphics. i have the following tables in the database:
table userinfo:
accno(P key), name,  balance
table pin:
accno(foreign key from userinfo), pin
I wrote the following code, however on running it shows nullpointer exception which I am unable to fix. I tried to find the point where the exception occurs by writing system.out.println("world"); in order to check which part of the code is wrong. I found that my try block is not working and I am unable to fix this. Please help me.
my code:
public void actionPerformed(ActionEvent evt) {
 try{
     System.out.println("world4");
 PreparedStatement ps=con.prepareStatement("Select * from pin where accno=? AND pin=?");
           System.out.println("world5");
  l1=Long.parseLong(acc);
        l2=Integer.parseInt(pin);
 ps.setLong(1,l1);
 ps.setInt(2,l2);
                System.out.println("world7");
 r=ps.executeQuery();
 PreparedStatement ps1=con.prepareStatement("Select * from pin where accno=?");
 ps1.setLong(1,Long.parseLong(tfnumber.getText()));
 r1=ps1.executeQuery();
 if(r.next())
 {
     m=new menu();
     setVisible(false);
     System.out.println("world1");
 }
 else if(r1.next())
         {   System.out.println("world2");
             lblerr=new Label("INVALID PIN!");
             lblerr.setBounds(470,400,80,30);
             img.add(lblerr);
             lblerr1.setVisible(false);
             lblerr.setVisible(true);
         }
 else
 {
     System.out.println("world3");
    lblerr1=new Label("ACCOUNT NOT FOUND");
     lblerr1.setBounds(370,300,80,30);
         img.add(lblerr1);
         lblerr.setVisible(false);
         lblerr1.setVisible(true);
  }
}
catch(Exception excp)
{
     System.out.println("world6");
     System.out.println(excp);
 }
here WORLD4,WORLD6 are printed on the screen, however, WORLD5&WORLD7 were not printed, indicating the non functional tryblock.
 
    