Code Fix

中級NullPointerException の原因と直し方 › パターン1

NullPointerException の原因と直し方

nullに対する操作で発生します。

 1  public class Main {
 2      public static void main(String[] args) {
 3          String s = ____;
                         ^
 4          System.out.println(s.length());
 5      }
 6  }
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.length()" because "s" is nullexited with code 1

空欄を埋めてビルドを通す

広告
広告スロット(未設定)

NullPointerException の原因と直し方

発生箇所の特定方法と、そもそもnullを持ち回さない設計を扱います。

このエラーの解説と類題をまとめて見る →

広告
広告スロット(未設定)