メソッドの外側のコンストラクターでオブジェクトをインスタンス化したいと思います。例:
public class Toplevel {
Configuration config = new Configuration("testconfig.properties");
public void method1() {
config.getValue();
...etc
}
}
今これを行うと...このエラーが発生します..
Default constructor cannot handle exception type IOException thrown by implicit super constructor. Must define an explicit constructor
クラスのどこでも構成を呼び出すことができるように、このようなことをしたいのですが、現在、構成オブジェクトをインスタンス化する必要があります...これを行う方法が必要です...どんな助けも大歓迎です.前もって感謝します。
編集:
構成クラス:
public class Configuration {
private String mainSchemaFile;
public Configuration() {
}
public Configuration( String configPath ) throws IOException {
Properties prop = new Properties();
prop.load( new FileInputStream( configPath ));
this.mainSchemaFile= prop.getProperty("MAINSCHEMA_FILE");
}