본문 바로가기

만났던 에러들

(3)
Cannot access database on the main thread since it may potentially lock the UI for a long period of time. 안드로이드에서 roomDB를 쓰는데 아래 에러를 만났다. Cannot access database on the main thread since it may potentially lock the UI for a long period of time. 우선 위의 에러를 해결한 방법을 설명하기 앞서서 하나 알아둬야 할게있다.안드로이드에선 외부통신(핸드폰 내부에 저장한 데이터 RoomDB나 SQLlite, Retrofit을 통해서 외부 api 통신에서도)을 메인 스레드에서 동작시키면 안된다.자 그렇다고 치더라도...뭔가 이상하다. 코루틴을 사용해서 veiwModelScope 에서 메소드를 실행하면 자동적으로 메인스레드가 아니라 워커 스레드에서 동작하는 것으로 알고 있는데 메인스레드에서 코드가 동작하고 있다는 말일..
android.os.BadParcelableException: Parcelable encountered IOException writing serializable object (name = model.Images) 아주 오래전에도 한번 만났던 오류인 것 같은데.. 에러가 발생했던 이유는... Serialize 할 수 없는 객체인 Uri를 DataClass 에서 사용하려고 했었기 때문이다. 아래 코드는 내가 작성한 Model 클래스다. import android.net.Uri import java.io.Serializable data class Images(val uri : Uri) : Serializable 이미지 하나만 보여주는 리사이클러뷰를 표현하기 위해서 위와 같이 개발했다. 갤러리에서 사진을 여러장 선택하면 사진 uri값이 list에 담기고, 인텐트를 사용해서 다음 화면(액티비티)로 넘겨주려고 했다. 해당 코드는 아래와 같다. ChooseMediaActivity.kt ... // onCreate 안이다. b..
java.lang.IllegalStateException: Flow invariant is violated:Emission from another coroutine is detected. 에러 내용 java.lang.IllegalStateException: Flow invariant is violated:Emission from another coroutine is detected. Child of StandaloneCoroutine{Active}@b93bc05, expected child of StandaloneCoroutine{Completed}@20ec45a. FlowCollector is not thread-safe and concurrent emissions are prohibited. To mitigate this restriction please use 'channelFlow' builder instead of 'flow' 아마 글자가 작아서 잘 안보이실분들을 위해서 사진으로..