Why does this give the error "cannot reference this before supertype constructor has been called"

I thought that is the first thing I did in the constructor.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package application1;

import java.awt.BorderLayout;
import java.beans.PropertyVetoException;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;

/**
 *
 * @author depot
 */
public class InternalFrame extends JInternalFrame {
    static final int xPosition = 30, yPosition = 30;
    public static int openFrameCount = 0;
    public String guideName = "guide";
    public JInternalFrame frame;
    //getGuideName() + (++openFrameCount), true, true, true, true

    public InternalFrame() throws FileNotFoundException, IOException {        
        super(getGuideName() + (++openFrameCount), true, true, true, true);
        System.out.println("internal frame openFrameCount= " + openFrameCount);
        setVisible(true);
        setSize(750, 500);
        setLocation(xPosition * openFrameCount, yPosition * openFrameCount);
        
    }
   
}

I think it is because when you call the super constructor, you have to pass values to it as parameters. In order to get the first the first argumnet this needs to be called:

super([B]getGuideName[/B]() + (++openFrameCount), true, true, true, true)

Meaning that when you do the above it is not the constructor that is called first. First the getGuideName is called in order to get the guide name, and then super is called with that value. And the super constructor always needs to be called first.

correct. You're calling a method on your object instance before that instance has been fully initialised.
In the call to super you can pass only constructor arguments and static method calls, not instance members and methods.

Thank you . I did not realize this. In fact the example I was using passed simple identifiers. Sounds perfectly logical and I will try it.
The class shown is a "word for word" extraction from my previous JDescktopPane class that held this class as a inner class. Have you explained this? Did it work there because the getter was of some different nature than my getter that calls before super()?

....

 public void createFrame(String ln) throws IOException, FileNotFoundException,
            PropertyVetoException {


        jdp.add(CreateNewGuide(ln));

    }//end createFrame()

    //__________________________________________________________________________CLASS
    ///////////////////////////////////////////////////////////////////////////
    //////////////////// create frame CLASS ///////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////
    public class InternalFrame extends JInternalFrame {

        static final int xPosition = 30, yPosition = 30;

        public InternalFrame() throws FileNotFoundException, IOException {
            super(getGuideName() + (++openFrameCount), true, true, true, true);
            System.out.println("internal frame openFrameCount= " + openFrameCount);
            setVisible(true);
            setSize(750, 500);
            setLocation(xPosition * openFrameCount, yPosition * openFrameCount);
        }
    }//ene class
    //end class
    ///////////////////////////////////////////////////////////////////////////
    ////////////////////             MENU           ///////////////////////////
    ///////////////////////////////////////////////////////////////////////////
    protected JMenuBar createMenuBar() {

        //Jmenu File
        JMenu jMenuFile = new JMenu("File");
        JMenu jMenuEdit = new JMenu("Edit");
        JMenu jMenuProject = new JMenu("Project");
        JMenu jMenuHelp = new JMenu("He......

for some reason the naming convention worked for every new InternalFrame.

This article has been dead for over six months. Start a new discussion instead.