我是一個java新手,所以如果這個問題聽起來很愚蠢,請原諒我。我正在學。空指針異常。爲什麼?
我想計算這個總數,但我得到一個奇怪的錯誤消息。你能幫我找到我嗎?非常感謝你
public class myfirstjavaclass {
public static void main(String[] args) {
Integer myfirstinteger = new Integer(1);
Integer mysecondinteger = new Integer(2);
Integer mythirdinteger = null;
Integer result = myfirstinteger/mythirdinteger;
}
}
Exception in thread "main" java.lang.NullPointerException
at myfirstjavaclass.main(myfirstjavaclass.java:8)
'mythirdinteger = null;'然後'myfirstinteger/mythirdinteger'這等於'1/null'? – MadProgrammer
爲什麼它不是零? – Mary
只是一個提示:'(myfirstjavaclass.java:8)'意味着它發生在第8行。那行上是否有空指針(「引用」)? –