this program calls another class when the credentials are passed into it. The issue is that an exception is occuring in the thread when the JFrame of the other class is being called (setVisible = 1).
Program:
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Login window = new Login();
window.frmLogin.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Login() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
public void initialize() {
frmLogin = new JFrame();
frmLogin.setTitle("Login");
frmLogin.setSize(500,300);
frmLogin.setResizable(false);
frmLogin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmLogin.getContentPane().setLayout(null);
user = new JTextField();
user.setBounds(204, 90, 86, 20);
frmLogin.getContentPane().add(user);
user.setColumns(10);
JLabel lblUsername = new JLabel("Username:");
lblUsername.setBounds(113, 90, 81, 20);
frmLogin.getContentPane().add(lblUsername);
JLabel lblPassword = new JLabel("Password:");
lblPassword.setBounds(113, 138, 81, 20);
frmLogin.getContentPane().add(lblPassword);
login = new JButton("Login");
login.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
String b = new String(pass.getPassword());
AdDAuthenticator adAuthenticator = new AdDAuthenticator();
Map<String,Object> attrs = adAuthenticator.authenticate(user.getText(), b);
if (attrs != null) {
for (String attrKey : attrs.keySet()) {
if (attrs.get(attrKey) instanceof String) {
System.out.println(attrKey +": "+attrs.get(attrKey));
} else {
System.out.println(attrKey +": (Multiple Values)");
for (Object o : (HashSet<?>)attrs.get(attrKey)) {
System.out.println("\t value: " +o);
}
}
}
updateScreen upd = new updateScreen();
frmLogin.dispose();
upd.frm.setVisible(true); //exception gets called.
} else {
System.out.println("Attributes are null!");
System.out.println(b);
System.out.println(user.getText());
JOptionPane.showMessageDialog(null, "Credentials are Incorrect", "Error" , JOptionPane.WARNING_MESSAGE);
System.exit(0);
}
}
});
login.setBounds(165, 195, 89, 23);
frmLogin.getContentPane().add(login);
pass = new JPasswordField();
pass.setBounds(204, 138, 86, 20);
frmLogin.getContentPane().add(pass);
lbljmawirelesscom = new JLabel("@.com");
lbljmawirelesscom.setBounds(300, 92, 110, 17);
frmLogin.getContentPane().add(#####);
}
}
the exception is given below:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Login$2.mouseClicked(Login.java:104)
at java.awt.AWTEventMulticaster.mouseClicked(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$500(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$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.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$JavaSecurityAccessImpl.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)
I am not sure as to why this is happening and i am not sure how to go about dealing with the exceptions. Let me know if you need more info.