Exceptions that are common in arrays

Source: Internet
Author: User

The common exceptions in the array are: 1, array subscript out of bounds exception 2, array null pointer exception, and NULL pointer exception is divided into 3 kinds, the code example is as follows:
public class Exception1 {
public static void Main (string[] args) {
1, array subscript subscript out of bounds exception: Java.lang.ArrayIndexOutOfBoundsException
int[] I=new int[10];
i[10] = 8;//subscript out of bounds
System.out.println (i[10]);

2. Null pointer exception java.lang.NullPointerException
First Kind
boolean[] B=new boolean[3];
b=null;//null pointer exception appears here
System.out.println (b[0]);

The second Kind
string[] Str=new string[5];
str[4]=new String ("AA");//or write str[3]= "AA" without writing this sentence will appear null pointer exception
System.out.println (str[4].tostring ());

Third Kind
Int[][] J=new int[3][];
j[1][0]=6;//first address is NULL, unable to find the specified value
}

}

Exceptions that are common in arrays

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.