-1

I am trying to pass/set the text from one jtextfield in a jframe (jTF1) to another jtextfield that is in another jframe (jTF2). But, after running the code, I am encountering an error that is mentioned above which means that the text from jTF1 can't be set to jTF2

This is Student_Dash class:-

  public class Student_Dash extends JFrame { 
    Connection con=null;
    ResultSet rs=null;
    Statement stmt;
    public JPanel contentPane = new JPanel();;
    JPanel Profile = new JPanel();
    private JTable table;
    private JTextField nameTA;
    private JTextField idTF;
    private String str;

    /**
     * Launch the application.
     */

     public static void main(String args[]){
          new Student_Dash();
         }
     
     public void my_update(String s) { //using this code to set value from textfield1 to idTF

            idTF.setText(s); //here the error is occurring
          } 
           /* rest code, 
            till the end */
            } 

and I am passing the text value using a variable, from homepage class through this code:-

public class homepage extends JFrame {
Student_Dash stdash=new Student_Dash();
String userid=textField.getText(); //getting value from textfield1
    stdash.my_update(userid);
        stdash.setVisible(true);
          }
  • It looks like you have never assigned a value to `idTF` – greg-449 May 11 '22 at 06:10
  • If you mean by setting a default value in idTF, I have tried that using idTF.setText("default"); . If I am wrong here, will you please guide me on how to correctly assign the value to idTF? Cuz idTF is a swing control so how can I use it as a variable to assign a value? – Yoshita Singh May 11 '22 at 10:45
  • Just declaring `idTF` just sets its value to null, you need to assign a value to it somewhere (often the class constructor). Something like `idTF = new JTextField();` – greg-449 May 11 '22 at 10:54
  • Oh! It worked! Thank you for your time and for helping me ^_^ – Yoshita Singh May 11 '22 at 21:42

0 Answers0