Saturday, 30 September 2017

java - Constructor call error message





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.


Answer



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());
}

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...