Common exceptions array

1. subscript bounds exception

2. null pointer exception

 

public  class TestException {
     public  static  void main (String [] args) {
         // array subscript bounds exception: java.lang.ArrayIndexOutOfBoundsException: 10 
        int [] I = new new  int [ 10 ];
 / *         I [0] = 99; 
        I [10] = 99; 
        for (int m = 0; m <i.length; m ++) { 
            System.out.println (I [m]); 
        } 
        
* / 
        // null pointer exception: java.lang.NullPointerException
         / / first: 
/ *         Boolean [] = new new Boolean B [. 3]; 
        B = null; // B is a null pointer is not original to an array of 
        System.out.println (b [0]);
* / 
        // second: 
/ *         String [] = new new STR String [. 4]; 
        System.out.println (STR [. 3] .toString ()); // STR [. 3] for the object itself is null method invocation is also null pointer exception 
* / 
        
        // third: 
/ *         int [] [] J = new new int [. 3] []; 
        J [2] [0] = 12 is; // se can not be assigned a null 
* / 
    } 
}

Guess you like

Origin www.cnblogs.com/afangfang/p/12460530.html