Error Message
error: incompatible types: String[] cannot be converted to char[]
번역 : 호환되지 않는 유형입니다: 문자열[]을 문자[]로 변환할 수 없습니다.
Cause
class Solution {
boolean solution(String s) {
int p = 0;
int y = 0;
char[] chars = s.toUpperCase().split(" ");
...
}
}
이 에러 메시지는 String[] 타입의 결과를 char[] 타입의 변수에 할당하려고 할 때 발생합니다.
split(" ") 메서드는 문자열을 분할하여 String[] (문자열 배열) 형태로 반환합니다.
그러나 코드에서는 char[] (문자 배열)로 이 결과를 받으려고 하고 있기 때문에 해당 에러가 발생했습니다.
Solution
class Solution {
boolean solution(String s) {
int p = 0;
int y = 0;
char[] chars = s.toUpperCase().toCharArray();
...
}
}
char[] 문자 배열로 만들어줘야 하기 때문에 split() 메서드 대신에 toCharArray() 메서드를 사용해서 에러를 해결할 수 있습니다.
'🖥 백엔드 개발 > 에러 및 예외처리' 카테고리의 다른 글
[Error] error: illegal start of type (0) | 2023.12.05 |
---|---|
[Error] error: no suitable method found for split(no arguments) (1) | 2023.11.25 |
[Exception] java.lang.ArrayIndexOutOfBoundsException: Index xout of bounds for length x (0) | 2023.11.21 |
[Error] error: unreachable statement (0) | 2023.11.19 |
[Error] error: possible lossy conversion from long to int (0) | 2023.11.18 |
Error Message
error: incompatible types: String[] cannot be converted to char[]
번역 : 호환되지 않는 유형입니다: 문자열[]을 문자[]로 변환할 수 없습니다.
Cause
class Solution {
boolean solution(String s) {
int p = 0;
int y = 0;
char[] chars = s.toUpperCase().split(" ");
...
}
}
이 에러 메시지는 String[] 타입의 결과를 char[] 타입의 변수에 할당하려고 할 때 발생합니다.
split(" ") 메서드는 문자열을 분할하여 String[] (문자열 배열) 형태로 반환합니다.
그러나 코드에서는 char[] (문자 배열)로 이 결과를 받으려고 하고 있기 때문에 해당 에러가 발생했습니다.
Solution
class Solution {
boolean solution(String s) {
int p = 0;
int y = 0;
char[] chars = s.toUpperCase().toCharArray();
...
}
}
char[] 문자 배열로 만들어줘야 하기 때문에 split() 메서드 대신에 toCharArray() 메서드를 사용해서 에러를 해결할 수 있습니다.
'🖥 백엔드 개발 > 에러 및 예외처리' 카테고리의 다른 글
[Error] error: illegal start of type (0) | 2023.12.05 |
---|---|
[Error] error: no suitable method found for split(no arguments) (1) | 2023.11.25 |
[Exception] java.lang.ArrayIndexOutOfBoundsException: Index xout of bounds for length x (0) | 2023.11.21 |
[Error] error: unreachable statement (0) | 2023.11.19 |
[Error] error: possible lossy conversion from long to int (0) | 2023.11.18 |