我有一個父類「Application Window」和一個子類「config」。當我創建一個「config」類的對象時,執行往往會進入一個循環並持續創建這個對象。程序在java中創建類對象時出現的問題
以下是代碼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();
}
}
兒童級 「配置」 下面:
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);
}
}
}
您似乎已經收到了很好的答案,但請記住您可以在代碼中添加斷點並在Eclipse中調試您的應用程序。這會讓你有機會確切地知道代碼的流動方式,看看出了什麼問題。 – Fredrik
感謝您的建議。但我一直記得這一點。 :) – deejaydrives