我在 Java 中有一个始终为 null 的值,但我不明白为什么,因为我正在使用类构造函数设置变量的值。
我有这样的代码:
Driver driverClass = new Driver("<file path redacted>");
然后是下面的:
String cfgFilePath;
public Driver(String cfgFile) {
this.cfgFilePath = cfgFile;
}
private ArrayList<String> keys = getKeys(cfgFilePath);
private String a1 = keys.get(0);
private String b1 = keys.get(1);
出于某种原因,IntelliJ IDEA 说 cfgFilePath 始终为空。我用 Driver 类构造函数初始化它,为什么它是空的?当我运行程序时,我得到一个空指针异常。
慕桂英4014372
相关分类