-1

I designed the login interface, and it compares the information that you entered with the information that is in the database. When I step on the login, this problem appears. I read about this problem and understood that it occurs when I call the value in the variable, but there is no value in the variable to call it.

But the variables that I want to compare with have values that I entered

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

        

//These are the variables in which the username and password that you entered are stored and compared to them
        
        String namee=name_admin.getText();
        int pass=Integer.parseInt(pass_admin.getText());   
        


        try {




    line 128     pre=con.prepareStatement("Select * from adminn where adm_name='"+namee+"' and adm_password='"+pass+"'");

            ru=pre.executeQuery();

            if (ru.next()) {

                System.out.println("login done");
            } else {
                System.out.println("login faild");
            }

        } catch (Exception er) {

            er.printStackTrace();

            System.out.println(er);
        }


    }                                           

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

        library ii = new library();

        dispose();

        ii.setVisible(true);


    }                                        

This is the code where the problem occurred

`

java.lang.NullPointerException
java.lang.NullPointerException
    at ad_login.admin_loginActionPerformed(ad_login.java:128)
    

Here is a screenshot of the database that I want to compare against screen shot of database

And this is a picture of my entries in the login interface

`screen shot of my input in login form

I checked the variables and it turned out that they are correct and there is nothing wrong with them

1 Answers1

0

On line 128,

 pre=con.prepareStatement("Select * from adminn where adm_name='"+namee+"' and adm_password='"+pass+"'");

Check the connection object, con, is the only object, on that line that can raise that exception.

mzm
  • 53
  • 3
  • [link https://l.top4top.io/p_2522drbji1.png ] I checked it and I think there is no error in it, and here is a screenshot of the code @mzm – Ahmed_tarek Nov 27 '22 at 05:29
  • @Ahmed_tarek no and nowhere should you post screenshots of code (or of any other plain text) - instead c&p and add it the question, best in the form of a [mcve] of a single problem. And while you are at editing: stick to java naming conventions when showing java code publicly (no underscores) – kleopatra Nov 27 '22 at 15:28