투케이2K

254. (TWOK/ERROR) [Flutter] null 삽입 - Unhandled Exception: Null check operator used on a null value 본문

투케이2K 에러관리

254. (TWOK/ERROR) [Flutter] null 삽입 - Unhandled Exception: Null check operator used on a null value

투케이2K 2024. 7. 20. 12:31
반응형

[환경 설정 및 설명]

프로그램 : Flutter

설 명 : [Flutter] null 삽입 - Unhandled Exception: Null check operator used on a null value

 

[에러 원인]

1. 초기 null 값으로 선언한 변수를 새로운 변수에 강제 대입 시 발생하는 이슈

    >> ex : int a? = null; >> int b? = a!!; (강제 대입)

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value
#0      main (package:flutter_project/main.dart:36:12)
#1      _runMain.<anonymous closure> (dart:ui/hooks.dart:301:23)
#2      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#3      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
 

[해결 방법]

1. Null Safe 안정성 방법으로 null 로 선언 된 변수 새롭게 할당 시 기본 값 지정 실시

    >> ex : int a? = null; >> int b? = a ?? 0; (null 일 경우 0 값 삽입)

 
반응형
Comments