package com.atguigu.java;
//1.下标越界ArrayIndexOutOfBoundsException
//2.空指针异常NullPointerException,只要调用属性或者方法的那个值为null就会发生该错误
public class ArrayExceptionTest {
public static void main(String[] args) {
//1.下标越界ArrayIndexOutOfBoundsException
int[] numbers = new int[2];
//System.out.println(numbers[2]);
//System.out.println(numbers[-1]);
//2.空指针异常NullPointerExceptionNullPointerException
String str = "aaa";
str = null;
//System.out.println(str.toUpperCase());
String[][] ps = new String[2][3];
System.out.println(ps[0][0].toUpperCase());//因为ps[0][0]的内容为null
}
}
java基础:数组中常见的异常
最新推荐文章于 2024-05-06 10:37:06 发布