public class LogGUI extends JFrame implements ActionListener
{
   /**
 * 
 */
private static final long serialVersionUID = 1L;
private JPanel logPanel,namePanel,passPanel,eePanel;
   private JTextField logname,logpass;
   private JLabel log,pass,inform;
   private JButton enter,exit;
   private int logtype;
public LogGUI()
   {
super("登陆界面");
       //-------------------------------------
  ................logPanel 中我定一了两个JButton 和两个JTextField
             用于接受帐号和密码
            一个确定按钮 一个退出按钮 两个用同一个监听
       //---------------------------------
       this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       this.getContentPane().add(logPanel);
       this.pack();
       
      }
public void actionPerformed(ActionEvent e)

  Object tmp = e.getSource();
  if(tmp==enter)//是确定按钮
  {
  int index ;  
  int length = Storage.managers.size() ;
 for(index = 0 ; index <length; index--)
     {
          if(Storage.managers.get(index).account == Long.getLong(logname.getText())&&Storage.managers.get(index).equalKey(logpass.getText()))//提示这句错误!!!
           {
              this.setVisible(false);
                      break;
           }
     }
 if(index == length)
 JOptionPane.showMessageDialog(null, "输入的密码不正确或者不存在这个帐号!");
           
   
   
   
   }
  
  
  }
  else if(tmp==exit)//退出
    System.exit(0); }
}
--------------------------------------------------------------------------
public class Storage {protected static ArrayList<Manager> managers = new ArrayList<Manager>();
public static  void initiate()

Manager aaa = new Manager("kangluyao",2004081314,"512276364");
Manager bbb = new Manager("sadfsd",2004081313,"123456");
    managers.add(aaa);
    managers.add(bbb);
}
--------------------------------------------------------------------------
出错提示是:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at debug.LogGUI.actionPerformed(LogGUI.java:75)
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.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)
-----------------------------------------------------------------------
为什么老提示空指针呢??
想不通阿~~~~~~~~~~~~~~~~~
能否有其他方法写这个登陆程序阿??
谢谢了

解决方案 »

  1.   

    for(index = 0 ; index <length; index--) //???
    怎么是index--? 应该是index++吧.
      

  2.   

    应该是for(index =0;index<length;index++)
    但是还是错误啊
    真的想不通
    我还用这个思想写了一个测试程序
    上面的方法就行得通,但上面的就运行出错请哪位指点一下吧
    谢谢
      

  3.   

    调用Storage前,先执行
    public static  void initiate()
    要不数据没初始化,使用就空指针了