Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppCompatTextView could not be instantiated

Tags:

android

I am having problems figuring out what to do to solve this error.
I tried invalidating caches/restart, freed up disk space and reinstalling Android Studio.

The following classes could not be instantiated:
    - android.support.v7.widget.AppCompatTextView(Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE.If this is an unexpected error you can also
try to build the project, then manually refresh the layout.Exception Details java.lang.NullPointerException
    at android.content.res.Resources_Delegate.getValue(Resources_Delegate.java: 788)   
    at android.content.res.Resources.getValue(Resources.java: 1286)   
    at android.support.v4.content.res.ResourcesCompat.loadFont(ResourcesCompat.java: 212)   
    at android.support.v4.content.res.ResourcesCompat.getFont(ResourcesCompat.java: 206)   
    at android.support.v7.widget.TintTypedArray.getFont(TintTypedArray.java:119)   
    at android.support.v7.widget.AppCompatTextHelper.updateTypefaceAndStyle(AppCompatTextHelper.java:208)   
    at android.support.v7.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:152)   
    at android.support.v7.widget.AppCompatTextHelperV17.loadFromAttributes(AppCompatTextHelperV17.java:38)   
    at android.support.v7.widget.AppCompatTextView. < init > (AppCompatTextView.java:81)   
    at android.support.v7.widget.AppCompatTextView. < init > (AppCompatTextView.java: 71)   
    at java.lang.reflect.Constructor.newInstance(Constructor.java: 423)   
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)   
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)   
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)   
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java: 858)   
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)   
    at android.view.LayoutInflater.rInflate(LayoutInflater.java: 834)   
    at android.view.LayoutInflater.inflate(LayoutInflater.java: 492)   
    at com.android.layoutlib.bridge.bars.CustomBar. < init > (CustomBar.java:95)   
    at com.android.layoutlib.bridge.bars.StatusBar. < init > (StatusBar.java: 67)   
    at com.android.layoutlib.bridge.impl.Layout.createStatusBar(Layout.java: 224)   
    at com.android.layoutlib.bridge.impl.Layout. < init > (Layout.java: 146)
like image 253
Kenyon Tan Avatar asked Sep 07 '17 13:09

Kenyon Tan


2 Answers

This appears to be a bug: Preview render problem when adding maven.google.com as a maven repo.

It is triggered if the new maven repo is used within the project level build.gradle:

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

Unfortunately, we don't seem to have another source for the most recent support library versions (26 and above) since they are apparently not present in the SDK Manager any more:

The support libraries are now available through Google's Maven repository. We no longer support downloading the libraries through the SDK Manager, and that functionality will be removed soon.

All of that said, this problem seems only to affect the designer in Android Studio. You should be able to build and run the app even though the designer complains.

What you apparently won't be able to do is see a nice, quick preview of your layout's TextView elements.

Finally, the designer preview does not seem to have this particular bug in Android Studio v3, which is currently in beta. So, you might want to upgrade and see how that works for you.

like image 163
albert c braun Avatar answered Sep 23 '22 05:09

albert c braun


Refer this answer here. Updating the current theme parent to Base theme in styles.xml seems working.

like image 35
SKR Avatar answered Sep 23 '22 05:09

SKR