habe ein fenster fürs einloggen geschrieben. es wird name und password geprüft und falls ok kann man sich einloggen.
ich bekomme folgende ewiglange fehlermeldung:
es handelt sich wenn ich es richtig sehe, um eine nullpointer exception an dieser stellen:
hab leider keine ahnung was ich falsch mache. hier der code des fensters. hoffe mir kann jemand helfen.
ich bekomme folgende ewiglange fehlermeldung:
Code:
java.lang.NullPointerException
at client.LoginWindow.actionPerformed(LoginWindow.java:114)
at javax.swing.JTextField.fireActionPerformed(JTextField.java:489)
at javax.swing.JTextField.postActionEvent(JTextField.java:670)
at javax.swing.JTextField$NotifyAction.actionPerformed(JTextField.java:784)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1512)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2435)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2470)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2398)
at java.awt.Component.processEvent(Component.java:4943)
at java.awt.Container.processEvent(Container.java:1566)
at java.awt.Component.dispatchEventImpl(Component.java:3639)
at java.awt.Container.dispatchEventImpl(Container.java:1623)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1688)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:593)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:765)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:698)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:559)
at java.awt.Component.dispatchEventImpl(Component.java:3509)
at java.awt.Container.dispatchEventImpl(Container.java:1623)
at java.awt.Window.dispatchEventImpl(Window.java:1590)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
es handelt sich wenn ich es richtig sehe, um eine nullpointer exception an dieser stellen:
Code:
if ( ! names[i].equals(nameTextField.getText()) )
hab leider keine ahnung was ich falsch mache. hier der code des fensters. hoffe mir kann jemand helfen.
Code:
/*
* Created on 27.11.2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package client;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
/**
* @author CHUCKY
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* Login to enter the main programm.
*/
public class LoginWindow implements ActionListener
{
private JButton loginButton;
private JButton cancelButton;
private JLabel nameLabel;
private JLabel passwordLabel;
private JTextField nameTextField;
private JTextField passwordTextfield;
private String[] names = { "kai", "gaby", "hans" };
private String[] passwords = { "a", "b", "c" };
private boolean isNameCorrect = false;
private boolean isPasswordCorrect = false;
/**
* Creates the Login Window.
*
*/
public LoginWindow()
{
JFrame iw = new JFrame("Login Window");
Container cp = iw.getContentPane();
cp.setLayout(new FlowLayout());
JLabel nameLabel = new JLabel("Enter Name: ");
JLabel passwordLabel = new JLabel("Enter Password");
JTextField nameTextField = new JTextField(30);
JTextField passwordTextField = new JTextField(30);
cp.add(nameLabel);
cp.add(nameTextField);
cp.add(passwordLabel);
cp.add(passwordTextField);
nameTextField.addActionListener(this);
passwordTextField.addActionListener(this);
nameTextField.setActionCommand("name");
nameTextField.setActionCommand("password");
loginButton = new JButton("Login");
cancelButton = new JButton("Cancel");
loginButton.addActionListener(this);
cancelButton.addActionListener(this);
loginButton.setActionCommand("login");
cancelButton.setActionCommand("cancel");
cp.add(loginButton);
cp.add(cancelButton);
iw.setSize(400, 200);
iw.setVisible(true);
//iw.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}
public void actionPerformed(ActionEvent evt)
{
if ( evt.getActionCommand().equals("name") )
{
for (int i=0; i<names.length; i++)
{
if ( ! names[i].equals(nameTextField.getText()) )
{
System.out.println("name incorrect");
}
else
{
System.out.println("name correct");
isNameCorrect = true;
}
}
}
if ( evt.getActionCommand().equals("password") )
{
for (int i=0; i<names.length; i++)
{
if ( ! passwords[i].equals(nameTextField.getText()) )
{
System.out.println("password incorrect");
}
else
{
System.out.println("password correct");
isPasswordCorrect = true;
}
}
}
if ( evt.getActionCommand().equals("login") )
{
if ( (isNameCorrect = true) && (isPasswordCorrect = true) )
{
System.out.println("Access allowed");
//open new window .....
}
else
{
System.out.println("Access denied. Enter name and password again");
}
}
}
}