Note that there are some explanatory texts on larger screens.

plurals
  1. POJava NullPointerException when there are no variables not initialiased
    primarykey
    data
    text
    <p>I am creating this login form using java swing and what I basically do is I get the values from the relevant JtextFields and send them onto another class. Thereafter I check it with the database records. However the program is always displaying a NullPointerException everytime I run it. I tested every variable and saw that none of them contain any Null Values at all.</p> <p>This is the first method (in the LoginPage class) that gets the values from the JTextField</p> <pre><code>public void actionPerformed(ActionEvent e) { String user=textField.getText(); String pass=String.valueOf(passwordField.getPassword()); //try{ //if((user!=null)&amp;&amp;(pass!=null)){ // System.out.println("user is not null"); ui.sendLogin(user,pass); //}else{} //}catch(NullPointerException ex){ //System.out.println("Entered catch block og view"+ex.getMessage()); //} </code></pre> <p>} </p> <p>Thereafter it calls this method (in class LoginController)</p> <pre><code>public void sendLogin(String user, String pass) { try{ System.out.println("values from sendLogin"+user+"pass"+pass); model.verifyUser(user,pass); }catch(NullPointerException ex){ System.out.println("Entered catch block os sendLogin"+ex); ex.printStackTrace(); } } </code></pre> <p>Finally the verifyUser method (in class LoginModel) checks it with the database</p> <pre><code> public void verifyUser(String user,String pass){ String username=""; String password=""; String acc=""; try{ String sql="SELECT * FROM users"; con1.getInstance(); Statement st = con1.getConn().createStatement(); ResultSet rs=st.executeQuery(sql); rs.next(); username=rs.getString("username"); password=rs.getString("password"); acc=rs.getString("accountType"); if(username.equals(user)&amp;&amp;password.equals(pass)){ System.out.println("Logged into the system"); global_username=username; accountType=acc; }else{ System.out.println("Unsuccessful login"+username+user+password+pass); } st.execute(sql); } catch (SQLException s){ System.out.println("SQL statement is not executed!"+s); } } </code></pre> <p>This is the Stack Trace</p> <pre><code>java.lang.NullPointerException at org.application.view.LoginController.sendLogin(LoginController.java:64) at org.application.view.LoginPage$2.actionPerformed(LoginPage.java:94) user is not null values from sendLoginapassabc Entered catch block os sendLoginjava.lang.NullPointerException 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$000(Unknown Source) at java.awt.EventQueue$1.run(Unknown Source) at java.awt.EventQueue$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$2.run(Unknown Source) at java.awt.EventQueue$2.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$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) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload