我将导航组件更新为2.3.2版本。
2.3.1版本中正常工作
我正在查看文档,但没有发现任何有关错误或组件中任何更新的信息
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.m.marketplace, PID: 16698
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.m.marketplace/com.m.marketplace.ui.MainActivity}: android.view.InflateException: Binary XML file line #11 in com.m.marketplace:layout/activity_main: Binary XML file line #11 in com.m.marketplace:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3311)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3460)
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:2047)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7590)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: android.view.InflateException: Binary XML file line #11 in com.m.marketplace:layout/activity_main: Binary XML file line #11 in com.m.marketplace:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: android.view.InflateException: Binary XML file line #11 in com.m.marketplace:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: java.lang.IllegalArgumentException
at androidx.lifecycle.LifecycleRegistry.downEvent(LifecycleRegistry.java:263)
at androidx.lifecycle.LifecycleRegistry.backwardPass(LifecycleRegistry.java:314)
at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:334)
at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:145)
at androidx.lifecycle.LifecycleRegistry.setCurrentState(LifecycleRegistry.java:118)
at androidx.navigation.NavBackStackEntry.updateState(NavBackStackEntry.java:150)
at androidx.navigation.NavBackStackEntry.setMaxLifecycle(NavBackStackEntry.java:130)
at androidx.navigation.NavController.popBackStackInternal(NavController.java:325)
at androidx.navigation.NavController.navigate(NavController.java:1050)
at androidx.navigation.NavController.navigate(NavController.java:942)
at com.m.marketplace.utils.ktx.NavControllerKt.navigateSafe(NavController.kt:17)
at com.m.marketplace.utils.ktx.NavControllerKt.navigateSafe$default(NavController.kt:13)
at com.m.marketplace.utils.ktx.FragmentKt.navigate(Fragment.kt:15)
at com.m.marketplace.ui.login.view.PreviousLoginDialog.goToHome(PreviousLoginDialog.kt:119)
at com.m.marketplace.ui.login.view.PreviousLoginDialog.access$goToHome(PreviousLoginDialog.kt:28)
at com.m.marketplace.ui.login.view.PreviousLoginDialog$firstInit$1.invoke(PreviousLoginDialog.kt:111)
at com.m.marketplace.ui.login.view.PreviousLoginDialog$firstInit$1.invoke(PreviousLoginDialog.kt:28)
at com.m.marketplace.ui.login.view.PreviousLoginDialog.onCreate(PreviousLoginDialog.kt:44)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2684)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:280)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1175)
at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2224)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1997)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1953)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849)
E/AndroidRuntime: at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2629)
at androidx.fragment.app.FragmentManager.dispatchCreate(FragmentManager.java:2571)
at androidx.fragment.app.Fragment.onCreate(Fragment.java:1685)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:264)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2684)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:280)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1175)
at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2224)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1997)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1953)
at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1818)
at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:303)
at androidx.fragment.app.FragmentContainerView.<init>(FragmentContainerView.java:166)
at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:51)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:135)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:356)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:335)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1073)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1001)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.m.marketplace.ui.MainActivity.onCreate(MainActivity.kt:50)
at android.app.Activity.performCreate(Activity.java:7893)
at android.app.Activity.performCreate(Activity.java:7880)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3286)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3460)
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:2047)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7590)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
4条答案
按热度按时间c3frrgcw1#
我也遇到了同样的问题,我发现Android Studio没有在导航图中添加名称标签。所以,在导航图xml中添加名称标签对我很有效。
在nav_graph.xml中
或者,如果您不确定,则切换到设计,并在右侧的属性选项卡中,从下拉列表中选择类名
y53ybaqx2#
如果使用
Jetpack Compose
,则将MainActivity
扩展为AppCompatActivity
,而不是CompatActivity
wlwcrazw3#
首先,请确保您已将ID添加到导航图和片段容器视图。还要检查片段(声明为开始目标)没有任何示例化问题。
ni65a41a4#
使用Koin时,在清单中的应用程序中添加
android:name=".MyApplication"
,修复了此错误和错误之前出现的“访问隐藏方法”警告