-6
請告知空指針異常是下面的檢查是因爲我試圖避免空指針異常正確,鄉親們請指教如何從這個試圖避免在以下環
if ((Integer.valueOf(subProductTolerancesMap.get(subProduct))!= null) && (Integer.valueOf(subProductTolerancesMap.get(maxSubProduct))!=null))
{}
請告知空指針異常是下面的檢查是因爲我試圖避免空指針異常正確,鄉親們請指教如何從這個試圖避免在以下環
if ((Integer.valueOf(subProductTolerancesMap.get(subProduct))!= null) && (Integer.valueOf(subProductTolerancesMap.get(maxSubProduct))!=null))
{}
這是克服不正確。如果你的subProductTolerancesMap爲null,你將得到一個帶有該代碼的NullPointerException。此外,如果subProductTolerancesMap.get(subProduct)爲null,或者subProductTolerancesMap.get(maxSubProduct)爲null,則將得到NumberFormatException。
提示:'Integer.valueOf'將*永遠不會*返回null ... – assylias
所以請告訴我們應該如何檢查 – user1529641
你是否需要這兩個值? – djointster