12

Here are my dependencies of build.gradle(app)

compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 
{
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.firebaseui:firebase-ui-auth:2.3.0'
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:design:26.0.1'
compile 'com.android.support:support-vector-drawable:26.0.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'

Here is a part of build.gradle(Project)

allprojects {
    repositories {
        jcenter()
        maven { url "https://maven.google.com" }
    }
}

When I am going to any xml file it is showing me an error **The following classes could not be instantiated:

 android.support.v7.widget.AppCompatTextView (Open Class, Show Exception, Clear Cache)**

I have updated Android Studio to the latest still it shows the error.

I am unable to figure out the problem.Thank you

Eco4ndly
  • 515
  • 1
  • 5
  • 22

7 Answers7

26

EDIT

Whenever You'll add maven repository, this problem will occur.
See same error I'm facing on a question asked by my friend here as I can't ask.

This can be solved by changing AppTheme in res -> values -> Styles.xml change your theme from

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

to

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

It solved mine and don't forget the actual answer.

Lalit Fauzdar
  • 5,953
  • 2
  • 26
  • 50
  • Yes. I changed to 26.0.0-alpha1 and the issue is resolved but when i am trying to use firebase ui library 26.0.1 version is required. How to use 26.0.1 version? – Eco4ndly Aug 25 '17 at 15:41
  • What about `NoActionBar` in `Base`. What is the replacement for `Theme.AppCompat.NoActionBar`? – Mario Velasco Sep 14 '17 at 16:32
  • @MarioVelasco you can use this very same theme as using noactionbar is not compulsory, even I don't have action bar but still I'm using this... It causes no conflict. – Lalit Fauzdar Sep 14 '17 at 16:36
  • @LalitSinghFauzdar `Base.Theme.AppCompat.Light.DarkActionBar` will create a default `ActionBar`. I 'm looking for a `NoActionBar` theme that solves the problem of this post. – Mario Velasco Sep 14 '17 at 16:43
  • @LalitSinghFauzdar The `ActionBar` created with the `Base.Theme.AppCompat.Light.DarkActionBar` is not in the xml, it cannot be deleted. – Mario Velasco Sep 14 '17 at 16:49
  • @LalitSinghFauzdar even an empty xml with that theme will create an `ActionBar` – Mario Velasco Sep 14 '17 at 16:56
  • 1
    I used the `Base` theme together with `false` and `true` in order to get an activity without `ActionBar` – Mario Velasco Sep 14 '17 at 17:17
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/154469/discussion-between-mario-velasco-and-lalit-singh-fauzdar). – Mario Velasco Sep 14 '17 at 17:22
4

I had the same error while using Theme.AppCompat.NoActionBar

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">

I replaced it by and it works fine:

<style name="AppTheme" parent="Base.Theme.AppCompat">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
Morteza Jalambadani
  • 2,190
  • 6
  • 21
  • 35
Slel
  • 63
  • 6
  • Thank you for this. I am going throw the book "Head First Android Development A Brain-Friendly Guide" And this is the only good solution on the internet. – Dime Jan 04 '22 at 18:19
3

In styles.xml,

Changing the theme from Theme.AppCompat.Light.DarkActionBar to Base.Theme.AppCompat.Light.DarkActionBar has worked for me.

Credit goes to: https://stackoverflow.com/a/45399080/8111914

Namita
  • 49
  • 9
3

If you have encountered one of these errors pasted below, you might need to review your settings in styles.xml files. I encountered this problem after I changed my build Tools in build.gradle file from buildToolsVersion '23.0.0' to buildToolsVersion '26.0.2'

To specifically solve the problem, if you have a line similar to this

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

change it to include the Base prefix, for instance in my case I changed from

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

to

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

and everything worked fine.

The following classes could not be instantiated:

- android.support.v7.widget.AppCompatImageView (Open Class, Show Exception, Clear Cache)

- android.support.v7.widget.AppCompatButton (Open Class, Show Exception, Clear Cache)

- android.support.v7.widget.Toolbar (Open Class, Show Exception, Clear Cache)

- android.support.v7.widget.AppCompatEditText (Open Class, Show Exception, Clear Cache)

- android.support.v7.widget.AppCompatTextView (Open Class, Show Exception, Clear Cache)

- android.support.v7.widget.ActionBarContextView (Open Class, Show Exception, Clear Cache)

- android.support.v7.app.WindowDecorActionBar (Open Class, Show Exception, Clear Cache)

- android.support.v7.widget.ActionBarOverlayLayout (Open Class, Show Exception, Clear Cache)
Lalit Fauzdar
  • 5,953
  • 2
  • 26
  • 50
crakama
  • 759
  • 11
  • 25
0

I had a hard corded color value and after removing it everything worked just fine

0

Please change the theme style in res -> values -> Styles.xml

From : <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

To : <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

-1

This can be solved by changing AppTheme in res -> values -> Styles.xml change your theme from

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

to

<style name="AppTheme" parent="Base.Theme.AppCompat">
Micer
  • 8,731
  • 3
  • 79
  • 73