- 相關(guān)推薦
java運(yùn)行異常的示例
NullPointerException:空指針異常類
示例:
package com.darkmi.basic;
public class Test {
public static void main(String[] args) {
System.out.println(toUpper(null));
}
public static String toUpper(String str){
return str.toUpperCase();
}
}
異常信息如下:Exception in thread "main" java.lang.NullPointerException
at com.darkmi.basic.Test.toUpper(Test.java:11)
at com.darkmi.basic.Test.main(Test.java:6)
ArrayIndexOutOfBoundsException:數(shù)組下標(biāo)越界異常
示例:
package com.darkmi.basic;
public class Test {
public static void main(String[] args) {
int[] a = {0,1,2,3};
System.out.println(a[4]);
}
}
【java運(yùn)行異常的示例】相關(guān)文章:
Java編程學(xué)習(xí)示例07-31
關(guān)于循環(huán)的java代碼示例09-26
Java編程中異常處理的方法10-02
Java程序開(kāi)發(fā)與運(yùn)行環(huán)境05-07
java system類使用方法示例10-09
java構(gòu)造函數(shù)實(shí)現(xiàn)代碼示例08-23