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