Tuesday, June 25, 2019

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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...