在JAVA中使用数组的注意事项:
1. NullPointerException空指针
NullPointerException在开发过程中经常遇到,例如引用的对象为空,数组为空。
数组NullPointerException
不能为空数组元素赋值或获取长度。 否则,我就报告你
nullpointerexception : attempttowritetonullarray和
nullpointerexceptionattempttogetlengthofnullarray在以下代码中引起上面两种空指针的异常:
数组NullPointerException Log示例
Log信息如下
第一次使用NullPointerException如下
2020-03-2117336005336014.170 eandroidruntime : caused by : Java.lang.nullpointerexception : attempttogetlengthof
17:05:14.170.62788398839 eandroidruntime : atcom.program Android.exception.nullpointerexception.araynullpon
2 .使用数组时,在判断数组的长度后,首先需要判断是否为空。