Android App Error: Unable to Start Activity Due to ActionBar Conflict
{"title": "2023-08-28 12:02:10.222 6298-6331 libEGL com.example.materialtest D Emulator has host GPU support, qemu.gles is set to 1.\n2023-08-28 12:02:10.223 6298-6331 libc com.example.materialtest W Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)\n2023-08-28 12:02:10.207 6298-6298 RenderThread com.example.materialtest W type=1400 audit(0.0:41): avc: denied { write } for name="property_service" dev="tmpfs" ino=8411 scontext=u:r:untrusted_app:s0:c138,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0\n2023-08-28 12:02:10.237 6298-6331 libEGL com.example.materialtest D loaded /vendor/lib/egl/libEGL_emulation.so\n2023-08-28 12:02:10.239 6298-6331 libEGL com.example.materialtest D loaded /vendor/lib/egl/libGLESv1_CM_emulation.so\n2023-08-28 12:02:10.241 6298-6331 libEGL com.example.materialtest D loaded /vendor/lib/egl/libGLESv2_emulation.so\n2023-08-28 12:02:10.252 6298-6298 AppCompatDelegate com.example.materialtest D Checking for metadata for AppLocalesMetadataHolderService : Service not found\n2023-08-28 12:02:10.285 6298-6298 le.materialtes com.example.materialtest W Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)\n2023-08-28 12:02:10.285 6298-6298 le.materialtes com.example.materialtest W Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)\n2023-08-28 12:02:10.291 6298-6298 AndroidRuntime com.example.materialtest D Shutting down VM\n2023-08-28 12:02:10.292 6298-6298 AndroidRuntime com.example.materialtest E FATAL EXCEPTION: main\n Process: com.example.materialtest, PID: 6298\n java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.materialtest/com.example.materialtest.MainActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.\n at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)\n at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)\n at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)\n at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)\n at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)\n at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)\n at android.os.Handler.dispatchMessage(Handler.java:107)\n at android.os.Looper.loop(Looper.java:214)\n at android.app.ActivityThread.main(ActivityThread.java:7356)\n at java.lang.reflect.Method.invoke(Native Method)\n at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)\n at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)\n Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.\n at androidx.appcompat.app.AppCompatDelegateImpl.setSupportActionBar(AppCompatDelegateImpl.java:630)\n at androidx.appcompat.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:185)\n at com.example.materialtest.MainActivity.onCreate(MainActivity.kt:14)\n at android.app.Activity.performCreate(Activity.java:7802)\n at android.app.Activity.performCreate(Activity.java:7791)\n at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)\n at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)\n at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)\n 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) 2023-08-28 12:02:10.298 6298-6298 Process com.example.materialtest I Sending signal. PID: 6298 SIG: 9
This error occurs when the app attempts to use a Toolbar while also having an existing ActionBar provided by the window decor. This conflict leads to the app crashing. To resolve this issue, you should disable the default ActionBar and utilize a Toolbar instead. You can achieve this by setting "windowActionBar" to "false" in your app's theme and using the "setSupportActionBar()" method to set the Toolbar as the ActionBar.
The error message specifies the issue occurs in the "onCreate" method of the "MainActivity" file, specifically at line 14 (com.example.materialtest.MainActivity.onCreate(MainActivity.kt:14)). You should review and adjust the code at this location to fix the conflict between the ActionBar and Toolbar.
In addition to the error message, the report also includes information about the emulator and graphics libraries. These details may not directly contribute to resolving the crash, but they could provide context for further analysis and debugging if necessary.
原文地址: https://www.cveoy.top/t/topic/qwxx 著作权归作者所有。请勿转载和采集!