使用navigation组件时,系统一直报错2024-01-21 16:37:44.126 5871-5871 AndroidRuntime com.example.outdoor E FATAL EXCEPTION: main
Process: com.example.outdoor, PID: 5871
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.outdoor/com.example.outdoor.activity.LoginActivity}: android.view.InflateException: Binary XML file line #13 in com.example.outdoor:layout/activity_login: Binary XML file line #13 in com.example.outdoor:layout/activity_login: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
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:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: android.view.InflateException: Binary XML file line #13 in com.example.outdoor:layout/activity_login: Binary XML file line #13 in com.example.outdoor:layout/activity_login: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #13 in com.example.outdoor:layout/activity_login: Error inflating class fragment
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f100000
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:237)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2281)
at android.content.res.Resources.getXml(Resources.java:1226)
at androidx.navigation.NavInflater.inflate(NavInflater.java:75)
at androidx.navigation.NavController.setGraph(NavController.java:557)
at androidx.navigation.NavController.setGraph(NavController.java:539)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:248)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:3094)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:504)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:268)
at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:142)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:136)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:247)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:226)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1069)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:775)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:197)
at com.example.outdoor.activity.LoginActivity.onCreate(LoginActivity.java:73)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
2024-01-21 16:37:44.126 5871-5871 AndroidRuntime com.example.outdoor E at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
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:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
然后反反复复为难ChatGPT,问题也无法解决,然后!
我参考了一下前辈大佬写的安卓Navigation系列——入门篇-腾讯云开发者社区-腾讯云,反反复复检查每个步骤每个代码,终于发现问题所在哈哈哈,
问题出在app找不到navigation文件夹,因为这个文件夹创建的时候没有选择navigation类型,这个问题太难找!