2012-01-09 72 views
0

我想一個新的則newkey-的NewValue對添加到我的配置性能在運行時文件。我試過:爪哇 - 添加新條目對到屬性文件中運行

Properties p = new Properties(); 
p.load(fileinpustream ...); 
... 
p.setProperty("NewKey","NewValue"); 
p.store(outputstream, "comment"); 

但我總是在setProperty行上得到一個NullPointerException。 什麼建議嗎?

謝謝。

+0

u能請張貼的完整代碼?着figr出從這個 – Harinder 2012-01-09 11:20:17

+1

我想你已經過修剪你的代碼參選,在'p.setProperty'線是罰款(其餘爲僞代碼,這使得它很難發現錯誤)。 – 2012-01-09 11:20:46

+1

看來問題是隱藏的「...」 =) – 4ndrew 2012-01-09 11:21:33

回答

5

確保你的 「的NewValue」 不是

這是Hashtable中,java.util.Properties

的父母......

public synchronized V put(K key, V value) { 
// Make sure the value is not null 
if (value == null) { 
    throw new NullPointerException(); 
} 

...

+0

+1針點回答 – 2012-01-09 11:25:22

+0

+1的唯一可能的答案截至目前:) – COD3BOY 2012-01-09 11:27:24

+0

設置‘值’時,從另一個我有另一個錯誤方法。現在一切正常! – Lahniep 2012-01-09 14:37:32