본문 바로가기

Framework/Spring

[Spring] byte 타입으로 변수 선언 시 java.lang.NullPointerException: null 에러발생

DTO에 private byte parity로 변수 "parity"를 byte타입으로 선언하였습니다.

 

java.lang.NullPointerException: null  에러가 발생했습니다.

 

이 에러는 parity 변수에 초기값을 주지 않았기 때문에, 해당 변수는 기본적으로 null 상태인데

byte 타입의 변수는 null값을 가질 수 없기 때문에,

이 변수가 null 상태에서 사용될 경우 java.lang.NullPointerException: null 오류가 발생했습니다.

따라서, 해당 변수에 초기값을 할당해주어야 합니다. 

 

ex) private byte parity = 0 -> null이 아닌 0으로 초기화