lminsu / MovieTrailer

0 stars 0 forks source link

크래시 디버깅 경험 #25

Open lminsu opened 15 hours ago

lminsu commented 15 hours ago

프래그먼트에 생성자 인자를 추가하면 가로모드 회전 시 에러 발생

image

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.movietrailer/com.example.movietrailer.MainActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.movietrailer.ui.main.MainFragment: could not find Fragment constructor
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3654)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806)
  at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5802)
  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5710)
  at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267)
  at android.os.Handler.dispatchMessage(Handler.java:107)
  at android.os.Looper.loop(Looper.java:237)
  at android.app.ActivityThread.main(ActivityThread.java:8167)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
 Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.movietrailer.ui.main.MainFragment: could not find Fragment constructor
  at androidx.fragment.app.Fragment.instantiate(Fragment.java:628)
  at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
  at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:483)
  at androidx.fragment.app.FragmentStateManager.<init>(FragmentStateManager.java:85)
  at androidx.fragment.app.FragmentManager.restoreSaveState(FragmentManager.java:2728)
  at androidx.fragment.app.Fragment.restoreChildFragmentState(Fragment.java:1890)
  at androidx.fragment.app.Fragment.onCreate(Fragment.java:1867)
  at androidx.fragment.app.Fragment.performCreate(Fragment.java:2949)
  at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:475)
  at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:278)
  at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:112)
  at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1647)
  at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3128)
  at androidx.fragment.app.FragmentManager.dispatchCreate(FragmentManager.java:3061)
  at androidx.fragment.app.FragmentController.dispatchCreate(FragmentController.java:240)
  at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:276)
  at com.example.movietrailer.MainActivity.onCreate(MainActivity.kt:10)
  at android.app.Activity.performCreate(Activity.java:7963)
  at android.app.Activity.performCreate(Activity.java:7952)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3629)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806) 
  at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5802) 
  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5710) 
  at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69) 
  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267) 
  at android.os.Handler.dispatchMessage(Handler.java:107) 
  at android.os.Looper.loop(Looper.java:237) 
  at android.app.ActivityThread.main(ActivityThread.java:8167) 
  at java.lang.reflect.Method.invoke(Native Method) 
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496) 
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100) 
lminsu commented 13 hours ago

뷰모델 생성 시점을 프래그먼트 생성 시점과 동일하게 하면 크래시 발생

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.movietrailer/com.example.movietrailer.MainActivity}: java.lang.IllegalStateException: Can't access ViewModels from detached fragment
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3654)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:8167)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: java.lang.IllegalStateException: Can't access ViewModels from detached fragment
    at androidx.fragment.app.Fragment.getViewModelStore(Fragment.java:398)
    at androidx.lifecycle.ViewModelProvider.<init>(ViewModelProvider.kt:127)
    at com.example.movietrailer.ui.pager.PagerFragment.makePagerViewModel(PagerFragment.kt:105)
    at com.example.movietrailer.ui.pager.PagerFragment.<init>(PagerFragment.kt:27)
    at com.example.movietrailer.MainActivity.onCreate(MainActivity.kt:17)
    at android.app.Activity.performCreate(Activity.java:7963)
    at android.app.Activity.performCreate(Activity.java:7952)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3629)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806) 
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267) 
    at android.os.Handler.dispatchMessage(Handler.java:107) 
    at android.os.Looper.loop(Looper.java:237) 
    at android.app.ActivityThread.main(ActivityThread.java:8167) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100) 
    ...