0

I have a string in one frame named uname.

uname = usrNameTxt.getText();
char[] pword = pwordTxt.getPassword();
String password = new String(pword);

and pointed that to the next frame by

 this.dispose();
 new SectionsFclty(uname).setVisible(true);

and in my another one (shown below) frame want the String uname...

  public SectionsFclty() {
    initComponents();   
}

 public SectionsFclty(String uname) {
    initComponents();
    jLabelUsername.setText(uname);
}

But in my second frame (SectionsFclty.java) error comes in

  private void initComponents() {

    jPanel1 = new javax.swing.JPanel();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jLabel1 = new javax.swing.JLabel();
    jLabelUsername = new javax.swing.JLabel();..............

 }  // shows an error now

following error

  error: illegal start of expression
private void initComponents() {
            new SectionsFclty().setVisible(true);

required: String found: no arguments reason: actual and formal argument lists differ in length Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Saranya Saru
  • 33
  • 2
  • 7

1 Answers1

0

You need to call the constructor with a String parameter.

SectionsFclty fclt = new SectionsFclty(uname);
fclt.setVisible(true);

Using two lines is not a strict requirement, but it helps seeing where errors happen. Chaining can be convenient and makes the code shorter, but at least as long as you are a beginner, try to keep things simple.

I do not recommend making uname static. Static is not usually needed, and tends to cause more problems than it solves.

kiheru
  • 6,588
  • 25
  • 31