Two common mistakes in the Java Learning array

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.