public class Geometry {
public static void main(String[] args) {
System.out.println(args[0]);
}
}
에러코드
위 코드를 컴파일하였을 때 오류가 발생하였다.
' Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0 at '
에러문
해결방법
위 오류는 배열을 잘못 참조했을때 나오는 오류이다.
때문에 자바 파일을 실행할 때 args에 인자를 넘겨주고 사용하면 에러가 해결된다.
java 파일이름.java 인자값 {인자값2} {인자값3} ...
위와 같이 파일 이름 뒤에 인자값을 넘겨주면 args배열에 순서대로 저장되게 된다.
ex)
java Geometry.java onw two three
'에러 모음 및 해결' 카테고리의 다른 글
Xcode에서 warning 표시 끄는법 (0) | 2022.10.14 |
---|---|
[ERROR | Python] AttributeError: 'builtin_function_or_method' object has no attribute 오류 (5) | 2022.06.04 |
댓글