0

Any ideas why I may be seeing the following message for this class?

package org.swx.nursing.tools.sqlfinder.gui;

import javax.swing.JPanel;
import java.awt.event.ActionListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class GuiTemplateImpl  extends JPanel implements ActionListener {

    public void createAndShowGUI(GuiTemplateCriteria guiCriteria) {
        super(new BorderLayout());


    }
}

Message

Description Resource    Path    Location    Type
Constructor call must be the first statement in a constructor   GuiTemplateImpl.java    /sqlfinder/src/main/java/org/swx/nursing/tools/sqlfinder/gui    line 29 Java Problem

I am not sure why this will not work. The error goes away when i remove the super(), so this seems to be causing some issues.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Rookie
  • 5,179
  • 13
  • 41
  • 65

2 Answers2

2

super() must exist in constructor not a method. like:

public final class GuiTemplateImpl  extends JPanel implements ActionListener {
    public GuiTemplateImpl(GuiTemplateCriteria guiCriteria) {
        super(new BorderLayout());
    }
}
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
chengpohi
  • 14,064
  • 1
  • 24
  • 42
  • thanks. that was the issue, i mistakenly used this by oversight :/ ...been a long day i guess – Rookie May 26 '15 at 01:38
2

super let you call base constructor or base method. It is not clear what exactly you trying to achieve:

  • if you trying to create constructor than its name must match type name. It is the only place where you can call base constructor with super(...), and as error message says it must be first statement:

Code:

public GuiTemplateImpl(GuiTemplateCriteria guiCriteria) {
    super(new BorderLayout());
}
  • if you are trying to create method that will call base implementation:

Code (probably not what you looking for based on arguments mismatch):

public GuiTemplateImpl(GuiTemplateCriteria guiCriteria) {
    super.GuiTemplateImpl(new BorderLayout());
}
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179