1. <tt id="5hhch"><source id="5hhch"></source></tt>
    1. <xmp id="5hhch"></xmp>

  2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

    <rp id="5hhch"></rp>
        <dfn id="5hhch"></dfn>

      1. java運行常見異常類型

        時間:2020-10-11 18:22:43 JAVA認證 我要投稿

        java運行常見異常類型

          java運行時常見異常有很多,下面總結了幾個JAVA中常見的RuntimeException:

          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:數組下標越界異常

          示例:

          package com.darkmi.basic;

          public class Test {

          public static void main(String[] args) {

          int[] a = {0,1,2,3};

          System.out.println(a[4]);

          }

          }

          異常信息如下:

          Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 4

          at com.darkmi.basic.Test.main(Test.java:7)

          ArithmeticExecption:算術異常類:

          示例:

          package com.darkmi.basic;

          public class Test {

          public static void main(String[] args) {

          int a = 10 / 0;

          System.out.println(a);

          }

          }

          異常信息如下:

          Exception in thread “main” java.lang.ArithmeticException: / by zero

          at com.darkmi.basic.Test.main(Test.java:6)

          ClassCastException:類型強制轉換異常

          示例:

          package com.darkmi.basic;

          public class Test {

          public static void main(String[] args) {

          testParse(“aaa”);

          }

          public static void testParse(Object str){

          Integer i = (Integer)str;

          }

          }

          異常信息如下:

          Exception in thread “main” java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

          at com.darkmi.basic.Test.testParse(Test.java:10)

          at com.darkmi.basic.Test.main(Test.java:6)

        【java運行常見異常類型】相關文章:

        java運行常見異常舉例10-16

        Java異常歸類匯總11-19

        Java程序開發與運行環境06-02

        Java內存溢出的類型12-13

        Java基本數據類型11-14

        關于Java編程的異常處理特殊情況11-06

        常見的廣告招牌類型09-15

        出國留學考試常見類型09-06

        java基礎知識:強制類型轉換07-03

        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码

        1. <tt id="5hhch"><source id="5hhch"></source></tt>
          1. <xmp id="5hhch"></xmp>

        2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

          <rp id="5hhch"></rp>
              <dfn id="5hhch"></dfn>