3

I am busy trying to implement The support library so that i can make use of AppCompatActivty

As far as I know I have everything in the correct place. But I am still getting the error.

styles.xml

<resources>        
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">            
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>       
</resources>

v21/styles.xml

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

<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>     
</resources>

manifest.xml

  <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher_on"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

activity.java

public class RegisterActivity extends AppCompatActivity

Now when I run my application and try open RegisterActivty I get the following error.

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tuta_me/activities.RegisterActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

I must have missed something somewhere. What am I doing wrong?

Mohammed Aouf Zouag
  • 17,042
  • 4
  • 41
  • 67
Zapnologica
  • 22,170
  • 44
  • 158
  • 253

2 Answers2

1

Add this

<style name="AppBaseTheme" parent="Theme.AppCompat.Light">            
</style>

in your v21/styles.xml file. Without it, <style name="AppTheme" parent="AppBaseTheme"> has no meaning.

Mohammed Aouf Zouag
  • 17,042
  • 4
  • 41
  • 67
0

Look at this, maybe helps: https://stackoverflow.com/a/53749686/6883143 This answer looks like:

I have same problem when I've migrate to androidx. I've solve this by simply updating from

implementation 'androidx.appcompat:appcompat:1.0.0'

to

implementation 'androidx.appcompat:appcompat:1.0.2'
Axbor Axrorov
  • 2,720
  • 2
  • 17
  • 35