简体   繁体   中英

trying to avoid null pointer exception in the below loop

Please advise is the below check is correct as as i am trying to avoid the null pointer exception , folks please advise how to overcome from this

if ((Integer.valueOf(subProductTolerancesMap.get(subProduct))!= null) && (Integer.valueOf(subProductTolerancesMap.get(maxSubProduct))!=null) )
{}

It is not correct. If your subProductTolerancesMap is null, you will get a NullPointerException with that code.

Further, if subProductTolerancesMap.get(subProduct) is null or if subProductTolerancesMap.get(maxSubProduct) is null, you will get a NumberFormatException.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM