删除nullpointer异常

时间:2016-07-30 21:05:28

标签: java nullpointerexception

我写了一个链接我的sql数据库和项目的代码。我一直在尝试创建一个带图形的ATM。我在数据库中有以下表格: 表userinfo: accno(P键),名称,余额 表针: accno(来自userinfo的外键),pin 我编写了以下代码,但是在运行时它显示了我无法修复的nullpointer异常。我试着通过编写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.找到发生异常的点。 我的代码:

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);
 }

这里WORLD4,WORLD6打印在屏幕上,然而,WORLD5& WORLD7未打印,表示非功能性tryblock。

0 个答案:

没有答案