我有一个带有配置文件的参数化构造函数的前馈类:
public Feedforward(String cfg) throws Exception {
super(cfg);
String tempstr = "";
int currNeuronNum = 0;
int currEdgeNum = 0;
int currLayerID = 0;
int count = 0;
if (!(type).equals("feedforward")) {
throw new Exception("cfgError: specify proper type")
//more code
}
其中 super(cfg) 调用 Network 类的构造函数,我在其中处理文件解析和通用字段的存储:
protected Network(String cfgPath) throws IOException, Exception {
String type;
String activationFunction;
double bias;
/*file reading stuff; checked with print statements and during
the creation of a Feedforward class, successfully prints
"feedforward" after reading type from file
*/
}
当我运行测试时,它会抛出 NullPointerException。前馈中的类型变量未分配存储在 cfgPath/cfg 文件中的值,因此出现异常。为什么构造函数链接不这样做,我该如何做不同的事情?