오류 내용 : 현재 관리하고 있는 티스토리에 공부중인 코틀린 코드를 올려놓았다. 이 코드를 복사하여 Play Ground에서 실행하려니 다음과 같은 오류가 발생했다.
//보조 생성자 사용 예제
class User(var name:String, var age:Int){
//이름만 초기화해주는 보조 생성자
constructor(name : String) : this(name, 0){//보조 생성자에서 기본 생성자를 호출
println("보조 생성자가 호출되었습니다.")
}
}
fun main(){
val user1 = User("Yoon",30)
val user2 = User("Tom",25)
val user3 = User("Sora")
val user4 = User("Noa")
}
/*오류 메시지
Expecting member declaration
Expecting member declaration
Expecting member declaration
Expecting member declaration
Expecting member declaration
Expecting member declaration
Expecting member declaration
Expecting member declaration
A type annotation is required on a value parameter
Parameters must have type annotation
Expecting an element
Unexpected tokens (use ';' to separate expressions on the same line)
Expecting an element
Unexpected tokens (use ';' to separate expressions on the same line)
Expecting an element
Unexpected tokens (use ';' to separate expressions on the same line)
Expecting an element
Unexpected tokens (use ';' to separate expressions on the same line)
Expecting an element
Unexpected tokens (use ';' to separate expressions on the same line)
Expecting an element
Unexpected tokens (use ';' to separate expressions on the same line)
*/
해결 방법 : 각 코드라인의 들여쓰기를 지웠다가 다시 수동으로 들여쓰기를 입력
[Kotlin]문자열을 한 문자씩 분해하기 : Chunked() (0) | 2023.01.01 |
---|---|
참고용으로 기록하는 Kotlin 에러 (0) | 2022.05.25 |