Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 6 v4.0 - Runtime crash #41

Open
pouriaalmassi opened this issue Jun 25, 2023 · 0 comments
Open

Chapter 6 v4.0 - Runtime crash #41

pouriaalmassi opened this issue Jun 25, 2023 · 0 comments

Comments

@pouriaalmassi
Copy link

pouriaalmassi commented Jun 25, 2023

There is a runtime exception in chapter 6 v4.0 of the book. Following chapter 6 the app will build and run but it will immediately crash. Looking at Logcat the reason is as follows:

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

This appears to be a result of the AndroidManifest.xml inheriting the theme from themes.xml

I was able to fix this by making the following changes:

In AndroidManifest.xml define the app theme to AppCompat.

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat"> <!-- Set to this theme -->

And removing the theme definition from themes.xml.

<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--
    <style name="Theme.YourAppName" parent="android:Theme.Material.Light.NoActionBar" />
-->
</resources>

Alternative solution.

AndroidManifest.xml:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.YOURAPP">

themes.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.YOURAPP" parent="@style/Theme.AppCompat" />
</resources>

More info at: https://stackoverflow.com/a/21815015/1004227

My environment:

Android Studio Flamingo | 2022.2.1 Patch 2
Build #AI-222.4459.24.2221.10121639, built on May 12, 2023
Runtime version: 17.0.6+0-17.0.6b802.4-9586694 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant