Obtain a text field entry from another class

微信扫一扫,分享到朋友圈

Obtain a text field entry from another class

I wanted to call an input from mainGui.java
to mainmenu.java
but it keep returns me NullPointException.

Below is my code for mainGui.java

String input;

public String user() {
        return input = logintext.getText();
}

private void submitbtnActionPerformed(java.awt.event.ActionEvent evt) {                                          

        String input = logintext.getText();
            String input2 = loginpassword.getText();
             try {
                    lectFunc = (lectFunc)lectRecord.get(input);
                    if(lectFunc == null){
                        JOptionPane.showMessageDialog(null,"Wrong username or password!");
                    } else if (lectFunc.getUser().equals(input) && lectFunc.getPass().equals(input2)){                       dispose();
                        new mainmenu().setVisible(true);
                    }
                    else {
                        JOptionPane.showMessageDialog(null,"Error");
                    }
                 } catch (Exception ex) {
                       ex.printStackTrace();
                 }
}

and code for mainmenu.java

public class mainmenu extends javax.swing.JFrame {
    lectFunc lectFunc;
    mainGui mainGui;

    public mainmenu() {
        final String user = mainGui.user();
        lectFunc.setUser(user);
        System.out.println(lectFunc.getUser());
        new mainGui().setVisible(false);
        initComponents();
    }

Is there any way to overcome this problem?

UPDATE: NPE

java.lang.NullPointerException
    at oodj.mainmenu.(mainmenu.java:9)
    at oodj.mainGui.submitbtnActionPerformed(mainGui.java:158)
    at oodj.mainGui.access$000(mainGui.java:8)
    at oodj.mainGui$1.actionPerformed(mainGui.java:52)

Line 9 : final String user = mainGui.user();

微信扫一扫,分享到朋友圈

Obtain a text field entry from another class

Kubernetes Add-ons for more Efficient Computing

上一篇

时尚单品来袭 vivo LOGO PHONE开售

下一篇

你也可能喜欢

Obtain a text field entry from another class

长按储存图像,分享给朋友