任何人都可以告訴我爲什麼我的屬性對象爲null嗎?我是否必須將它傳遞給方法,還是有更好的方法?如果我需要在包之間傳遞屬性對象,該怎麼辦?謝謝!在我的程序周圍傳遞私有實例屬性對象
public class Test {
private Properties properties = null;
public static void main (String[] args) {
testObject = new Test();
Properties properties = new Properties(); // Then load properties from fileInputStream sucessfully
utilityMethod();
}
private void utilityMethod() {
properties.getProperty("test"); // Why do I get a null pointer exception?
}
}
你應該閱讀 - http://docs.oracle.com/javase/tutorial/java/javaOO/variables.html –
,因爲你沒有將Test.properties設置爲其他任何內容。 –