2016-04-27 42 views
0

我的項目文件夾結構如下(硒+ TestNG的)空指針誤差從另一個包讀取屬性文件時

PROJ
- 數據文件夾
---General.properties
- - src文件夾
--- libraby包 ----library.java
--testcases包 --- testcase1(TestNG的試驗,延伸庫)

問題:讀取library.java中的常規屬性文件時出現空指針,但放入testcase中的@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);} 
+0

您的用戶名拼寫錯誤。 – shmosel

回答

0

空指針異常是因爲public static Properties Prop = null;使得空

爲了克服這個public static Properties Prop = new Properties();是用來

可能是你在你的測試用例某處初始化Prop對象,因此它正常工作

+0

感謝Harshavardhan和雅有道理,我從來沒有初始化任何地方的對象只是一個null,我直接試圖加載它。 –

相關問題