kotlin エラー「error: unresolved reference」の解決方法

kotlinで、エラー「error: unresolved reference」の解決方法を記述してます。定義されていない変数を使用した際になどに発生します。
環境
- OS windows11 home
- java 17.0.2
- kotlin 1.6.10-release-923
エラー全文
以下のコードで発生。
fun main() {
val d = 10
println(a)
}
エラーメッセージ
error: unresolved reference: a
println(a)
原因
変数「a」が定義されていないため
対処法
定義されている変数を使用するか、変数を定義する
fun main() {
val a = 10
println(a)
}
-
前の記事
sqlite エラー「Error: multi-character column separators not allowed for import」の解決方法 2023.03.07
-
次の記事
kotlin エラー「error: the floating-point literal does not conform to the expected type Float」の解決方法 2023.03.07
コメントを書く