public class LoginCumReg implements ActionListener,KeyListener {
        private JFrame form;
        private JTextField txtunm;
        private JTextField txtnm;
        private JTextField txteml;
        private JButton cmdcreate;
        private JPasswordField txtpass;
        private JPasswordField txtpassreg;
        private JButton cmdok;
        private JLabel lblunm;
        private JLabel lblpass;
        private JLabel lbleml;
        private JLabel lblpassreg;
        private JLabel lblnm;
        private JPanel panel_1;
    public LoginCumReg() {
        // construct components
        form = new JFrame("Sign Up");
        form.getContentPane().setFont(
                new Font("Plantagenet Cherokee", Font.BOLD, 18));
        txtunm = new JTextField(5);
        txtunm.addKeyListener(this);
        txtunm.setBounds(637, 55, 100, 25);
        txtnm = new JTextField(5);
        txtnm.setBounds(637, 228, 100, 25);
        txteml = new JTextField(5);
        txteml.setBounds(637, 264, 100, 25);
        cmdcreate = new JButton("Create Account");
        cmdcreate.setBounds(527, 350, 188, 25);
        txtpass = new JPasswordField(5);
        txtpass.setBounds(637, 91, 100, 25);
        txtpassreg = new JPasswordField(5);
        txtpassreg.setBounds(637, 300, 100, 25);
        cmdok = new JButton("OK");
        cmdok.setBounds(527, 139, 100, 25);
        lblunm = new JLabel("UserName");
        lblunm.setBounds(527, 55, 73, 25);
        lblpass = new JLabel("Password");
        lblpass.setBounds(527, 91, 100, 25);
        lbleml = new JLabel("Email ID");
        lbleml.setBounds(527, 264, 100, 25);
        lblpassreg = new JLabel("Password");
        lblpassreg.setBounds(527, 300, 100, 25);
        lblnm = new JLabel("Full Name");
        lblnm.setBounds(527, 228, 100, 25);

        // form.setResizable(false);

        // adjust size and set layout
        form.setPreferredSize(new Dimension(800, 450));

        form.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        form.getContentPane().setLayout(null);

        // add components
        form.getContentPane().add(txtunm);
        form.getContentPane().add(txtnm);
        form.getContentPane().add(txteml);
        form.getContentPane().add(cmdcreate);
        form.getContentPane().add(txtpass);
        form.getContentPane().add(txtpassreg);
        form.getContentPane().add(cmdok);
        form.getContentPane().add(lblunm);
        form.getContentPane().add(lblpass);
        form.getContentPane().add(lbleml);
        form.getContentPane().add(lblpassreg);
        form.getContentPane().add(lblnm);

        cmdcreate.setActionCommand("Create Account");
        cmdcreate.addActionListener(this);
        cmdok.setActionCommand("Login");

        JPanel panel = new JPanel();
        panel.setBounds(502, 29, 254, 154);
        panel.setFont(new Font("Palatino Linotype", Font.PLAIN, 14));
        panel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.RAISED,
                null, null), "LOGIN", TitledBorder.LEADING, TitledBorder.TOP,
                null, null));
        panel.setBackground(SystemColor.controlHighlight);
        form.getContentPane().add(panel);

        panel_1 = new JPanel();
        panel_1.setBounds(500, 204, 254, 186);
        panel_1.setFont(new Font("Palatino Linotype", Font.PLAIN, 14));
        panel_1.setBorder(new TitledBorder(new EtchedBorder(
                EtchedBorder.RAISED, null, null), "SIGN UP",
                TitledBorder.LEADING, TitledBorder.TOP, null, null));
        panel_1.setBackground(SystemColor.controlHighlight);
        form.getContentPane().add(panel_1);

        JLabel lblNewLabel = new JLabel("New label");
        lblNewLabel.setBounds(91, 139, 286, 101);
        lblNewLabel.setIcon(new ImageIcon(
                "C:\\Users\\JAsh\\Desktop\\Projects\\JAsh.png"));
        form.getContentPane().add(lblNewLabel);

        JPanel panel_2 = new JPanel();
        panel_2.setBounds(77, 118, 315, 145);
        panel_2.setBorder(new EtchedBorder(EtchedBorder.RAISED,
                SystemColor.activeCaptionBorder, SystemColor.menu));
        panel_2.setBackground(SystemColor.controlHighlight);
        form.getContentPane().add(panel_2);
        cmdok.addActionListener(this);

        form.setResizable(false);
        form.pack();
        form.setVisible(true);
        System.out.println("const..");
    }

    public static void main(String[] args) {
        new LoginCumReg();
    }

    @Override
    public void actionPerformed(ActionEvent ae) {
        // TODO Auto-generated method stub

        if (ae.getActionCommand().equals("Create Account")) {
            new Registration(txtnm.getText(), txteml.getText(), new String(
                    txtpassreg.getPassword()));
            form.setVisible(false);
        }

        if (ae.getActionCommand().equals("Login")) {
            try {
                if (txtunm.getText().equalsIgnoreCase("admin")
                        && new String(txtpass.getPassword()).equals("admin")) {
                    form.setVisible(false);
                    new Admin();
                } else {
                    DataBase db = new DataBase();
                    db.connect();
                    String sql = "SELECT * FROM LOGIN WHERE USERNAME='"
                            + txtunm.getText() + "'";
                    ResultSet rs = db.getDDL(sql);
                    boolean found = false;
                    while (rs.next()) {
                        if (rs.getString("Password").equals(
                                new String(txtpass.getPassword()))) {
                            found = true;
                            form.setVisible(false);
                            String name = rs.getString("FullName");
                            Session.startSession(txtunm.getText(), name);
                            new FacultyWelcome();
                        }
                    }
                    if (!found)
                        JOptionPane.showMessageDialog(new JFrame(),
                                "Invalid Credentials");
                    db.close();
                }
            } catch (Exception e) {
            }
        }

    }

    @Override
    public void keyPressed(KeyEvent arg0) {
        // TODO Auto-generated method stub
    }

    @Override
    public void keyReleased(KeyEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void keyTyped(KeyEvent arg0) {
        // TODO Auto-generated method stub
    //  JOptionPane.showMessageDialog(new JFrame(), arg0.getKeyChar()+"-"+arg0.getKeyCode());

    }
}

上面的代码在我朋友的笔记本电脑上运行良好,并在我的笔记本电脑上抛出此错误.我已经使用Java7在EclipseJuno上运行了代码.我还在笔记本电脑上测试并运行了很多java程序,都运行得很好.这是唯一一个出现这种错误的程序.这是我最后一年的项目,我需要它在我的笔记本电脑上工作,我会对任何帮助我的人都很好

推荐答案

Solution 1:右键单击包含main方法的类.点击"运行方式".点击"Java应用程序".键盘快捷键是:Shift+Alt+X J(按住Shift和Alt的同时,按X;然后松开Shift和Alt并按J).

Solution 2:作为@Professor mentioned,请确保java -versionjavac -version是相同的.

Note:解决方案1是一个快速解决方案,对我和其他一些人都有效.它可能对你有用,也可能不管用.我认为解决方案2是解决这个问题的正确方法.

Mysql相关问答推荐

在SQL中连接两个表,从第一个表中 Select 随机行

拒绝非超级用户访问停靠的MariaDB(超级用户工作)

MySQL有没有办法直接从CSV文件中读取而不是导入它?

返回包含某一列的分组最大值的行,说明列中的重复值

带有值分隔的MySQL分组不起作用

Python - 执行原始 SQL 时获取更新查询 (Mysql) 的结果

DJANGO 使用原始 MYSQL 查询计算记录数并在 html 模板中使用结果

替代对多个表执行 FULL OUTER JOIN?

for each 查询设置 MySQL @@session.time_zone 而不是 CONVERT_TZ 的缺点?

如何计算每行的剩余金额?

相关查询 - 在派生表中,我可以有多个嵌套级别吗?

MYSQL:范围匹配与周年纪念日

为什么一个 10 位的电话号码不能存储在长度为 10 的整数中?

MYSQL除以零警告,奇怪的行为

SUBSTRING_INDEX 获取第 n 个值

MySQL 查询组按日期(12 小时间隔)

按长度过滤 varbinary 字段

Facebook user_id:big_int、int 还是 string?

用于国际和多语言目的的数据库建模

哪个更好 - 许多小桌子或一张大桌子?