-1

This issue has been an ache for me and i'm not entirely sure what's causing it any help would be appreciated.

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tencil/com.example.tencil.login}: android.view.InflateException: Binary XML file line #73 in com.example.tencil:layout/activity_login: Binary XML file line #73 in com.example.tencil:layout/activity_login: Error inflating class Button

 Caused by: android.view.InflateException: Binary XML file line #73 in com.example.tencil:layout/activity_login: Binary XML file line #73 in com.example.tencil:layout/activity_login: Error inflating class Button
 Caused by: android.view.InflateException: Binary XML file line #73 in com.example.tencil:layout/activity_login: Error inflating class Button
 Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat (or a descendant).

Now I've googled this issue countless of times and I can't see where I'm going wrong any help would be appreciated.

<Button
    android:id="@+id/btn_login"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/password"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="15dp"
    android:layout_marginRight="20dp"
    android:backgroundTint="#14b9d5"
    android:fontFamily="@font/roboto_regular"
    android:text="@string/login"
    android:textColor="@android:color/white" />
   <!--  android:background="@drawable/btn_custom"-->

GETTING THIS PROBLEM NOW:

Hey Team, 

I have this issue now : Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

enter code here

3 Answers3

0

You can try to create a style file and override the theme to see if it changes something and so you will know if its your android setup messing things up or your code.

  • Hey Team, I have this issue now : Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. – Ryan Kimber Jan 13 '21 at 12:58
0

Your root styles.xml

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar" tools:override="true">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

Your AndroidManifest.xml

    <application
    android:name="YOUR APPLICATION NAME OR DELETE"
    android:allowBackup="false"
    android:icon="@mipmap/ic_launcher_2"
    android:theme="@style/AppTheme">

This will work.

March3April4
  • 2,131
  • 1
  • 18
  • 37
0

I hope this helps.

Theme Fix. Go to res/values/styles.xml and make sure the style with name="AppTheme" has parent that is "Theme.AppCompat"

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

If you are using a different style, it's parent also has to be "Theme.AppCompat" like below.

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

Check your AndroidManifest.xml and find the activity. Make sure it references the style that has a parent of "Theme.AppCompat" like below

    <activity
        android:name=".Activities.MyActivity" android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen" />
Junior
  • 1,007
  • 4
  • 16
  • 26
  • Hey Team, I have this issue now : Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. any ideas – Ryan Kimber Jan 13 '21 at 12:58
  • I have made some changes to the answer I provided. Hope it helps. But seriously, add "+" after "@" in the xml "android:layout_below="@id/password" to make it " "android:layout_below="@+id/password". – Junior Jan 13 '21 at 13:24