【发布时间】:2017-01-18 09:02:06
【问题描述】:
我知道getFlightKey 在初始化过程中返回 null。它应该为空,因为我正在使用我的代码为两种类型的用户构建 apk。对于一个用户,使用“flight Key”,而对于另一个用户,则不使用它。
else {
tabletMetadata = new TabletMetadata(new DateTime(), getActiveEmployeeIdentifier()
,getAirFiApplication().getTabletId(),getFlightMetadata().get().getFlightKey()
,flightLegIdentifier, new DateTime(), level,
location != null ? String.valueOf(location.getLatitude()) : null,
location != null ? String.valueOf(location.getLongitude()) : null, null, level, null, null);
getFlightMetadata().get().getFlightKey() 将为空,但我如何添加类似于空检查的内容来处理这个?
【问题讨论】:
-
可能是
try { // your code } catch (NullPointerException npe){ // handle it here }? -
抓到 NPE 是不是很糟糕。
-
这样更好吗?
assert getFlightMetadata().get().getFlightKey() != null?
标签: android pointers exception null