从另一个包读取 属性 文件时出现空指针错误
Null pointer error when reading a property file from another package
我的项目文件夹结构如下(Selenium +testng)
项目
--数据文件夹
---General.properties
--src文件夹
---libraby包
----library.java
--测试用例包
---testcase1(testng测试,扩展库)
问题:在 library.java 中读取通用属性文件时为空指针,但将相同的代码放在测试用例的 @test 方法中时工作正常。为什么会这样?我只想读取库中的属性,我该怎么办?请帮忙
public class Library{
public static Properties Prop = null;
public static FileInputStream sFileIn = null;
public static final String sProjpath = System.getProperty("user.dir").toString();
public void Initialization () throws Throwable
{
sFileIn = new FileInputStream(sProjpath+"\Data\General.properties");
Prop.load(sFileIn);}
空指针异常是因为public static Properties Prop = null;
使其为空
要克服这个public static Properties Prop = new Properties();
就是要用
可能是您正在初始化测试用例中某处的 Prop
对象,所以它工作正常
我的项目文件夹结构如下(Selenium +testng)
项目
--数据文件夹
---General.properties
--src文件夹
---libraby包
----library.java
--测试用例包
---testcase1(testng测试,扩展库)
问题:在 library.java 中读取通用属性文件时为空指针,但将相同的代码放在测试用例的 @test 方法中时工作正常。为什么会这样?我只想读取库中的属性,我该怎么办?请帮忙
public class Library{
public static Properties Prop = null;
public static FileInputStream sFileIn = null;
public static final String sProjpath = System.getProperty("user.dir").toString();
public void Initialization () throws Throwable
{
sFileIn = new FileInputStream(sProjpath+"\Data\General.properties");
Prop.load(sFileIn);}
空指针异常是因为public static Properties Prop = null;
使其为空
要克服这个public static Properties Prop = new Properties();
就是要用
可能是您正在初始化测试用例中某处的 Prop
对象,所以它工作正常