空指针异常?
java
public HeartTime() {
this.redisCache = SpringUtils.getBean(RedisCache.class);
this.mqttGateway = SpringUtils.getBean(MqttGateway.class);
this.topic = "test";
}
@Override
public void run() {
while (count <= 3) {
sum++;
if (redisCache.getCacheObject("heart")) {
redisCache.deleteObject("heart");
count = 0;
}
if (redisCache.getCacheObject("heart")) { 这一行出现空指针异常,但我的redisCache也不是null。就很迷
redisCache不是null,但是redisCache.get的结果是个null
你把null直接放if里进行判断能不报错吗,if里需要的是个bool类型
可能是因为没拿到这个缓存,导致结果为空,报异常
getCacheObject这个方法里面是不是出现了空指针?