무슨 오류인가요?
조회수 2528회
Exception in thread "main" java.lang.NumberFormatException: For input string: "" at java.base/java.lang.NumberFormatException.forInputString(Unknown Source) at java.base/java.lang.Integer.parseInt(Unknown Source) at java.base/java.lang.Integer.parseInt(Unknown Source) at rew.Project7의1.main(Project7의1.java:29)
if(n==1) { System.out.println("계좌번호입력: "); String x = sc.nextLine(); x = x.replaceAll("-",""); accountNumber = Integer.parseInt(x); //문자열을 숫자로 변환
29번줄입니다. 위에거는. 맨위에 거는 오류의 내용이고요. 무엇이 잘못된것인가요? accountNumber은 위에서 int로 선언해놨습니다.
-
(•́ ✖ •̀)
알 수 없는 사용자
2 답변
-
public class Test { public static void main(String[] args) { String str = ""; int i = Integer.parseInt(str); System.out.println(i); } }
Exception in thread "main" java.lang.NumberFormatException: For input string: "" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:592) at java.lang.Integer.parseInt(Integer.java:615) at Test.main(Test.java:7)
본인이 그렇게 설계했으니까 공백이지 않을까요? x 값을 출력해보세요.
-
(•́ ✖ •̀)
알 수 없는 사용자
-
-
x 가 공백인것 같습니다. 공백 체크를 한번해보세요
-
(•́ ✖ •̀)
알 수 없는 사용자
-
댓글 입력