Connecting the stack of the previous Java exploration, and the inner exploration of erasing, you can learn two ways to master array errors.
Packagecom.dreamly.day01;/** * @authordreamly **/ Public classArrayTest01 { Public Static voidMain (string[] args) {int[] x=New int[3]; X=NULL;//erases the connection to the instance object, that is, the address value is not saved. System.out.println (x[0]); //nullpointerexception: null pointer exception, when reference does not have any point to a value of NULL, the reference is also used to manipulate the entity /*** Exception in thread ' main ' java.lang.NullPointerException at Com.dreamly.day01.ArrayTest01.main (arraytes T01.JAVA:11)*/ int[] arr=New int[3]; System.out.println (arr[3]); //arrayindexoutofboundsexception: When manipulating an array, it accesses a corner label that does not exist in the array 00000 /** Exception in thread ' main ' Java.lang.arrayindexoutofboundsexception:3 at com.dreamly.day01.ArrayTest01 . Main (arraytest01.java:19)*/ }}
Two common mistakes in the Java Learning array