카테고리 없음

[Trouble Shooting]'int java.lang.Number.intValue()' on a null object reference

데자와 맛있다 2023. 10. 1. 01:04
FATAL EXCEPTION: main
Process: com.habit, PID: 29808
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Number.intValue()' on a null object reference
at com.habit.data.repository.datasourceImpl.LocalDataSourceImpl.selectTodaysCalorie(LocalDataSourceImpl.kt:21)
at com.habit.data.repository.datasourceImpl.LocalDataSourceImpl$selectTodaysCalorie$1.invokeSuspend(Unknown Source:15)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8762)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@5d08197, Dispatchers.Main.immediate]

room 쿼리중에 sum 같은게 있나 확인하자

아무 데이터도 없는데 sum쿼리를 하면 null을 반환한다

이렇게 null반환으로 하고 (사실 쿼리중에서 값이 없으면 다른 값으로 변경하는게 있다)

이렇게 쓰는데서 null처리