Program stucks on creation of class object in java

I have a parent class "Application Window" and a child class "config". When I am creating an object of "config" class execution tends to go into a loop and keeps on creating this object.

Following is the code snipppet:

public class ApplicationWindow implements ActionListener{
    public String workSpace;
    public String logFile;
    public JFrame frmGenericAutomationFramework;
    public JProgressBar progressBar;
    public File currentTestSuiteFolder;
    public String currentTestSuiteName;

    config cfg;
    SettingsFrame settingsFrame;
    TestSuiteFrame testSuiteFrame;
    PromptTestSuiteName testSuitePrompt;

    public ApplicationWindow (){
        initialize();

        //**cfg  = new config();**
        cfg.readProperties();
    }
}

Child class "config" below:

public class config extends ApplicationWindow{
    String str;
    File cfgfile;
    FileOutputStream out;
    FileInputStream in;
    Properties props;

    String filepath = "D:/Webdriverwork/GAF/res/elements.properties";

    public config (){
        try{
            cfgfile = new File(filepath);
            in = new FileInputStream(cfgfile);
            props = new Properties();       
        }

        catch (Exception e){
            // Log message in log file
            String message = e.getMessage();

            System.out.println(message);

            // Exit the system
            System.exit(0);
        }
    }

    public void readProperties (){
        try{
            props.load(in);

            workSpace = props.getProperty("WORKSPACE");
            logFile = props.getProperty("LOGFILE");
        }
        catch (Exception e){
            // Log message in log file
            String message = e.getMessage();

            System.out.println(message);

            // Exit the system
            System.exit(0);
        }
    }

    public void updateProperty (String key, String value){
        try{
            props.setProperty(key,value);
        }
        catch (Exception e){
            // Log message in log file
            String message = e.getMessage();

            System.out.println(message);

            // Exit the system
            System.exit(0);
        }       
    }

    public void writeProperties (){
        try{
            in.close();
            out = new FileOutputStream(cfgfile);
            props.store(out, null);
            out.close();
        }
        catch (Exception e){
            // Log message in log file
            String message = e.getMessage();

            System.out.println(message);

            // Exit the system
            System.exit(0);
        }
    }
}
Jon Skeet
people
quotationmark

This is the problem:

public class config extends ApplicationWindow

in conjunction with this in the ApplicationWindow constructor:

cfg  = new config();

So to create a new ApplicationWindow, you need to create a new config... but that's an ApplicationWindow itself, so it'll create another config... which will in turn create another config etc.

Why would config extend ApplicationWindow? That sounds like an odd design to me - a configuration isn't a window. Just get rid of that extends specification and you might find everything else works.

Additionally, I would strongly advise you to follow Java naming conventions (use PascalCase for class names, for example) and make all of your fields private.

people

See more on this question at Stackoverflow