int x;この例では、変数 x はデフォルトで 0 に設定され、2 行目の値 5 は x が指すメモリ位置に書き込まれます。Javaはプログラマがメモリボックスを操作することを禁じており、オブジェクトのメソッドにのみアクセスでき、メモリの場所にはアクセスできません。
x = 5;
Point dot = null;
dot.getX();
スレッド "main" の例外 java.lang.NullPointerException2) null オブジェクトのインスタンスへのアクセスまたは変更。
at Test.main(Test.java:27)
Point dot = null;
dot.getX();
スレッド "main"の例外 test.main(Test.java:38)3)でjava.lang.NullPointerException
IOException nullException = null;
try {
throw nullException;
} catch (IOException e) {
e.printStackTrace();
}
char[] ch = null;5) 配列などのヌル位置にアクセスする場合
int length = ch.length;
char[] ch = null;
char c = ch[0];
Thread th=null;
synchronized(th){
System.out.print("このスレッドは同期されています");
}
void display(String phrase){オブジェクトがnullであるため、display()プロシージャでは何も起こらないため、この解決策は最適ではない場合があります。
//文がnullでないかチェック
if(phrase!=null)
System.out.print(phrase);
}
String string="";
//宣言
Thread[] th=new Thread[3];
//初期化
th[0]=new Thread();
th[1]=new Thread();
th[2]=new Thread();
Please disable your ad blocker and refresh the window to use this website.