初級 › cannot find symbol (variable) の原因と直し方 › パターン3
cannot find symbol (variable) の原因と直し方
変数名のタイプミス、宣言忘れ、スコープ外参照の3パターンに分けて原因を切り分けます。
1 public class Main { 2 public static void main(String[] args) { 3 if (true) { 4 int inner = 1; 5 } 6 System.out.println(__________); ^ 7 } 8 }
Main.java:6: error: cannot find symbol
symbol: variable inner
空欄を埋めてビルドを通す
波括弧の中で宣言した変数は、その括弧を出た時点で消えます。これをスコープと呼びます。
次の問題