E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
时间: 2023-06-16 19:05:14 浏览: 305
这个错误通常表示你的代码中有一个数组没有被正确初始化,因此它的长度为 null,无法获取其长度。你可以检查你的代码并确保所有的数组都被正确初始化。你还可以尝试使用断言来确保数组不为 null。例如:
```java
assert myArray != null;
int length = myArray.length;
```
这样,如果 myArray 为 null,代码就会抛出 AssertionError,而不是 NullPointerException。
相关问题
select COLLECT_TIME, PERF_VALUE, t1.unit, RULEA, RULEB, RULEC from ( select COLLECT_TIME, PERF_VALUE, UNIT as unit, EQP_OBJ_ID, OBJECT_TYPE, INDEX_TYPE, DEVICE_ID, INDEX_NAME from t_perf_sensor_history tpsh, t_perf_defined tpd where PERF_OBJ_ID = tpd.OBJ_ID ) as t1 left join t_alarm_rule tar on IF(tar.ALARM_OBJECT_TYPE = t1.DEVICE_ID, tar.ALARM_OBJECT_TYPE = t1.DEVICE_ID, tar.ALARM_OBJECT_TYPE = OBJECT_TYPE) where 1=1 and COLLECT_TIME BETWEEN DATE_SUB(NOW(), INTERVAL 53 DAY) AND NOW() union select COLLECT_TIME, PERF_VALUE, t1.unit, RULEA, RULEB, RULEC from ( select COLLECT_TIME, PERF_VALUE, UNIT as unit, EQP_OBJ_ID, OBJECT_TYPE, INDEX_TYPE, DEVICE_ID, INDEX_NAME from t_perf_sensor_run tpsr, t_perf_defined tpd where PERF_OBJ_ID = tpd.OBJ_ID ) as t1 left join t_alarm_rule tar on IF(tar.ALARM_OBJECT_TYPE = t1.DEVICE_ID, tar.ALARM_OBJECT_TYPE = t1.DEVICE_ID, tar.ALARM_OBJECT_TYPE = OBJECT_TYPE) where 1=1 and COLLECT_TIME BETWEEN DATE_SUB(NOW(), INTERVAL 53 DAY) AND NOW() order by COLLECT_TIME desc怎么优化速度
首先,可以优化查询语句中的子查询,将其转换为 JOIN。例如:
```
SELECT COLLECT_TIME, PERF_VALUE, tpd.UNIT AS unit, t1.EQP_OBJ_ID, t1.OBJECT_TYPE, t1.INDEX_TYPE, t1.DEVICE_ID, t1.INDEX_NAME, tar.RULEA, tar.RULEB, tar.RULEC
FROM (
SELECT tpsh.COLLECT_TIME, tpsh.PERF_VALUE, tpsh.EQP_OBJ_ID, tpsh.OBJECT_TYPE, tpsh.INDEX_TYPE, tpsh.DEVICE_ID, tpsh.INDEX_NAME
FROM t_perf_sensor_history tpsh
JOIN t_perf_defined tpd ON tpsh.PERF_OBJ_ID = tpd.OBJ_ID
WHERE tpsh.COLLECT_TIME BETWEEN DATE_SUB(NOW(), INTERVAL 53 DAY) AND NOW()
UNION ALL
SELECT tpsr.COLLECT_TIME, tpsr.PERF_VALUE, tpsr.EQP_OBJ_ID, tpsr.OBJECT_TYPE, tpsr.INDEX_TYPE, tpsr.DEVICE_ID, tpsr.INDEX_NAME
FROM t_perf_sensor_run tpsr
JOIN t_perf_defined tpd ON tpsr.PERF_OBJ_ID = tpd.OBJ_ID
WHERE tpsr.COLLECT_TIME BETWEEN DATE_SUB(NOW(), INTERVAL 53 DAY) AND NOW()
) t1
LEFT JOIN t_alarm_rule tar ON (tar.ALARM_OBJECT_TYPE = t1.DEVICE_ID OR tar.ALARM_OBJECT_TYPE = t1.OBJECT_TYPE)
ORDER BY COLLECT_TIME DESC
```
这样可以避免重复子查询的问题,提高查询效率。
其次,可以考虑对表进行索引优化。在这个查询中,可以为 t_perf_sensor_history 表的 COLLECT_TIME 字段和 PERF_OBJ_ID 字段,以及 t_perf_sensor_run 表的 COLLECT_TIME 字段和 PERF_OBJ_ID 字段建立联合索引,以优化子查询的效率。
最后,可以考虑对 WHERE 子句中的日期范围限制进行优化。例如,可以根据业务需求调整日期范围的大小,避免查询过多无用数据。同时,可以考虑将日期范围限制转换为日期时间戳的形式,以避免对日期字符串的转换和比较,提高查询效率。
select DISTINCT COLLECT_TIME, PERF_VALUE, t1.unit, RULEA, RULEB, RULEC, EQP_OBJ_ID, tar.OBJECT_ID from ( select COLLECT_TIME, PERF_VALUE, UNIT as unit, EQP_OBJ_ID, OBJECT_TYPE, INDEX_TYPE, DEVICE_ID, INDEX_NAME from t_perf_sensor_history tpsh, t_perf_defined tpd where PERF_OBJ_ID = tpd.OBJ_ID ) as t1 left join t_alarm_rule tar on IF(tar.ALARM_OBJECT_TYPE = t1.DEVICE_ID, tar.ALARM_OBJECT_TYPE = t1.DEVICE_ID, tar.ALARM_OBJECT_TYPE = OBJECT_TYPE) where 1=1 and COLLECT_TIME BETWEEN DATE_SUB(NOW(), INTERVAL 1 DAY) AND NOW() and EQP_OBJ_ID = '30625d79-56ae-4576-b278-24a7a1684856' and INDEX_NAME = '距离' 加上判断EQP_OBJ_ID, tar.OBJECT_ID是否相等
如果要加上判断EQP_OBJ_ID和tar.OBJECT_ID是否相等,可以使用一个子查询来先去重,然后再加上判断条件。例如:
```
SELECT COLLECT_TIME, PERF_VALUE, unit, RULEA, RULEB, RULEC, EQP_OBJ_ID, OBJECT_ID
FROM (
SELECT DISTINCT t1.COLLECT_TIME, t1.PERF_VALUE, t1.unit, t1.RULEA, t1.RULEB, t1.RULEC, t1.EQP_OBJ_ID, tar.OBJECT_ID
FROM (
SELECT COLLECT_TIME, PERF_VALUE, UNIT AS unit, EQP_OBJ_ID, OBJECT_TYPE, INDEX_TYPE, DEVICE_ID, INDEX_NAME
FROM t_perf_sensor_history tpsh, t_perf_defined tpd
WHERE PERF_OBJ_ID = tpd.OBJ_ID
) AS t1
LEFT JOIN t_alarm_rule tar ON IF(tar.ALARM_OBJECT_TYPE = t1.DEVICE_ID, tar.ALARM_OBJECT_TYPE = t1.DEVICE_ID, tar.ALARM_OBJECT_TYPE = OBJECT_TYPE)
WHERE COLLECT_TIME BETWEEN DATE_SUB(NOW(), INTERVAL 1 DAY) AND NOW()
AND EQP_OBJ_ID = '30625d79-56ae-4576-b278-24a7a1684856'
AND INDEX_NAME = '距离'
) AS t2
WHERE EQP_OBJ_ID = OBJECT_ID;
```
这样可以先用子查询将EQP_OBJ_ID和OBJECT_ID去重,然后再筛选出相等的记录。
阅读全文