{"id":465,"date":"2022-09-24T16:03:00","date_gmt":"2022-09-24T08:03:00","guid":{"rendered":"https:\/\/qaqaq.top\/?p=465"},"modified":"2022-11-27T12:40:00","modified_gmt":"2022-11-27T04:40:00","slug":"%e6%95%b0%e7%bb%84-%e6%95%b0%e7%bb%84%e4%b8%ad%e7%9a%84%e5%b8%b8%e8%a7%81%e5%bc%82%e5%b8%b8","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=465","title":{"rendered":"\u6570\u7ec4-\u6570\u7ec4\u4e2d\u7684\u5e38\u89c1\u5f02\u5e38"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P172;\n\/*\n * \u6570\u7ec4\u4e2d\u7684\u5e38\u89c1\u5f02\u5e38\uff1a\n * 1. \u6570\u7ec4\u89d2\u6807\u8d8a\u754c\u7684\u5f02\u5e38\uff1aArrayIndexOutOfBoundsExcetion\n * \n * 2. \u7a7a\u6307\u9488\u5f02\u5e38\uff1aNullPointerException\n * \n * \n *\/\npublic class ArrauExceptionTest {\n\tpublic static void main(String&#91;] args) {\n\t\t\n\t\t\/\/1. \u6570\u7ec4\u89d2\u6807\u8d8a\u754c\u7684\u5f02\u5e38\uff1aArrayIndexOutOfBoundsExcetion\n\t\tint&#91;] arr = new int&#91;] {1,2,3,4,5};\n\t\t\n\t\tfor(int i = 0; i &lt;= arr.length; i++) {\n\t\t\tSystem.out.println(arr&#91;i]);\n\t\t}\n\t\t\n\t\tSystem.out.println(arr&#91;-2]);\n\t\t\n\t\tSystem.out.println(\"hello\");\n\t\t\n\t\t\/\/2. \u7a7a\u6307\u9488\u5f02\u5e38\uff1aNullPointerException\n\t\t\/\/\u60c5\u51b5\u4e00\uff1a\n\t\tint&#91;] arr1 = new int&#91;] {1,2,3};\n\t\tarr1 = null;\n\t\tSystem.out.println(arr1&#91;0]);\n\t\t\n\t\t\/\/\u60c5\u51b5\u4e8c\uff1a\n\t\tint&#91;]&#91;] arr2 = new int&#91;4]&#91;];\n\t\tSystem.out.println(arr2&#91;0]&#91;0]);\n\t\t\n\t\t\/\/\u60c5\u51b5\u4e09\uff1a\n\t\tString&#91;] arr3 = new String&#91;] {\"AA\",\"BB\",\"CC\"};\n\t\tarr3&#91;0] = null;\n\t\tSystem.out.println(arr3&#91;0].toString());\n\t}\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[46],"class_list":["post-465","post","type-post","status-publish","format-standard","hentry","category-java-code","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/465"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=465"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/465\/revisions"}],"predecessor-version":[{"id":466,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/465\/revisions\/466"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}