Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The following classes could not be instantiated android.support.v7.widget.AppCompatTextView

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

like image 946
Eco4ndly Avatar asked Aug 24 '17 14:08

Eco4ndly


4 Answers

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>
like image 147
Slel Avatar answered Nov 08 '22 21:11

Slel


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)
like image 31
crakama Avatar answered Nov 08 '22 20:11

crakama


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.

like image 25
Lalit Fauzdar Avatar answered Nov 08 '22 20:11

Lalit Fauzdar


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

like image 3
Namita Avatar answered Nov 08 '22 21:11

Namita