๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๋นˆ ๊ตฌ๋ฉ ์ฑ„์šฐ๊ธฐ

[Android] java.lang.IllegalStateException: Can't access the Fragment View's LifecycleOwner when getView() is null i.e., before onCreateView() or after onDestroyView()

๋กœ๊ทธ ํ™•์ธ

java.lang.IllegalStateException: Can't access the Fragment View's LifecycleOwner when getView() is null i.e., before onCreateView() or after onDestroyView()

 

ํ”„๋ž˜๊ทธ๋จผํŠธ์˜ onCreate() ์•ˆ์—์„œ getViewLifeCycleOwner() ๋ฅผ ํ˜ธ์ถœํ•ด์„œ ๋ฐœ์ƒํ•œ ์ด์Šˆ์ด๋‹ค.

 

1.

Fragment.java์˜ getViewLiveCycleOwner()๊ฐ€ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ณ€์ˆ˜๋ฅผ ํ™•์ธํ–ˆ๋‹ค.

    // This is initialized in performCreateView and unavailable outside of the
    // onCreateView/onDestroyView lifecycle
    @Nullable FragmentViewLifecycleOwner mViewLifecycleOwner;

2.

ํ”„๋ž˜๊ทธ๋จผํŠธ์˜ ๋ผ์ดํ”„์‚ฌ์ดํด์„ ํ™•์ธํ–ˆ๋‹ค.

์ถœ์ฒ˜ : https://developer.android.com/guide/fragments/lifecycle

์ฃผ์„๊ณผ ํ”„๋ž˜๊ทธ๋จผํŠธ ๋ทฐ ๋ผ์ดํ”„์‚ฌ์ดํด์„ ๋ณด๋‹ˆ onCreateView() ์ด์ „์˜ onCreate()์—์„œ ํ”„๋ž˜๊ทธ๋จผํŠธ์˜ view lifecycler owner๋ฅผ ํ˜ธ์ถœํ•œ ๋‚ด ์ž˜๋ชป์ด ๋งž๋‹ค.

 

-> ํ”„๋ž˜๊ทธ๋จผํŠธ์˜ ๋ผ์ดํ”„์‚ฌ์ดํด๊ณผ ํ”„๋ž˜๊ทธ๋จผํŠธ ๋ทฐ์˜ ๋ผ์ดํ”„์‚ฌ์ดํด์€ ๋ณ„๊ฐœ๋ผ๋Š” ๊ฒƒ์„ ์•ž์œผ๋กœ๋Š” ์žŠ์ง€ ์•Š๊ธฐ๋ฅผ.

'๋นˆ ๊ตฌ๋ฉ ์ฑ„์šฐ๊ธฐ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Programming] Backpressure  (0) 2021.03.02
[Kotlin Coroutines] Channels  (0) 2021.03.02
[Kotlin Coroutines] ObsoleteCoroutinesApi  (0) 2021.02.24
[Android] AndroidManifest <receiver>  (0) 2021.02.23
[Android] android.intent.action.MY_PACKAGE_REPLACED  (0) 2021.02.23