question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to inflate ColorStateList, leaving it to the framework

See original GitHub issue

I create vertical stepper using this third party library.

Everything work on my android 5.1.1 and 11

But I have android 5.1.1 custom ROM to MIUI global stable 9 and CodeView said error

2022-03-26 14:37:19.556 4083-4083/com.sasmitadeveloper.java W/ResourcesCompat: Failed to inflate ColorStateList, leaving it to the framework
    java.lang.RuntimeException: Failed to resolve attribute at index 0
        at android.content.res.TypedArray.getColor(TypedArray.java:403)
        at android.content.res.XResources$XTypedArray.getColor(XResources.java:1296)
        at androidx.core.content.res.ColorStateListInflaterCompat.inflate(ColorStateListInflaterCompat.java:160)
        at androidx.core.content.res.ColorStateListInflaterCompat.createFromXmlInner(ColorStateListInflaterCompat.java:125)
        at androidx.core.content.res.ColorStateListInflaterCompat.createFromXml(ColorStateListInflaterCompat.java:104)
        at androidx.core.content.res.ResourcesCompat.inflateColorStateList(ResourcesCompat.java:229)
        at androidx.core.content.res.ResourcesCompat.getColorStateList(ResourcesCompat.java:203)
        at androidx.core.content.ContextCompat.getColorStateList(ContextCompat.java:519)
        at androidx.appcompat.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:48)
        at com.google.android.material.resources.MaterialResources.getColorStateList(MaterialResources.java:60)
        at com.google.android.material.button.MaterialButtonHelper.loadFromAttributes(MaterialButtonHelper.java:108)
        at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:246)
        at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:217)
        at java.lang.reflect.Constructor.newInstance(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
        at android.view.LayoutInflater.createView(LayoutInflater.java:611)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:747)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:810)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:508)
        at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
        at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:334)
        at android.view.LayoutInflater.inflate(<Xposed>)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:418)
        at ernestoyaquello.com.verticalstepperform.StepHelper.initialize(StepHelper.java:68)
        at ernestoyaquello.com.verticalstepperform.VerticalStepperFormView.initializeStepHelper(VerticalStepperFormView.java:837)
        at ernestoyaquello.com.verticalstepperform.VerticalStepperFormView.initializeForm(VerticalStepperFormView.java:823)
        at ernestoyaquello.com.verticalstepperform.Builder.init(Builder.java:539)
        at com.sasmitadeveloper.java.MainActivity.onCreate(MainActivity.java:35)
        at android.app.Activity.performCreate(Activity.java:6093)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2404)
        at android.app.ActivityThread.access$900(ActivityThread.java:154)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1315)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5296)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)
        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)

at first i thought error in VerticalStepperLibrary but when I remove pattern in code view, everything work. Of cours codeView will not showing any color. This is my pattern class, copy from example in this project

public class PatternTools {

    //Language Keywords
    private static final Pattern PATTERN_KEYWORDS = Pattern.compile("\\b(abstract|boolean|break|byte|case|catch" +
            "|char|class|continue|default|do|double|else" +
            "|String|true|false" +
            "|enum|extends|final|finally|float|for|if" +
            "|implements|import|instanceof|int|interface" +
            "|long|native|new|null|package|private|protected" +
            "|public|return|short|static|strictfp|super|switch" +
            "|synchronized|this|throw|transient|try|void|volatile|while)\\b");

    private static final Pattern PATTERN_BUILTINS = Pattern.compile("[,:;[->]{}()]");
    private static final Pattern PATTERN_COMMENT = Pattern.compile("//(?!TODO )[^\\n]*" + "|" + "/\\*(.|\\R)*?\\*/");
    private static final Pattern PATTERN_ATTRIBUTE = Pattern.compile("\\.[a-zA-Z0-9_]+");
    private static final Pattern PATTERN_OPERATION = Pattern.compile(":|==|>|<|!=|>=|<=|->|=|>|<|%|-|-=|%=|\\+|\\-|\\-=|\\+=|\\^|\\&|\\|::|\\?|\\*");
    private static final Pattern PATTERN_GENERIC = Pattern.compile("<[a-zA-Z0-9,<>]+>");
    private static final Pattern PATTERN_ANNOTATION = Pattern.compile("@.[a-zA-Z0-9]+");
    private static final Pattern PATTERN_TODO_COMMENT = Pattern.compile("//TODO[^\n]*");
    private static final Pattern PATTERN_NUMBERS = Pattern.compile("\\b(\\d*[.]?\\d+)\\b");
    private static final Pattern PATTERN_CHAR = Pattern.compile("'[a-zA-Z]'");
    private static final Pattern PATTERN_STRING = Pattern.compile("\".*\"");
    private static final Pattern PATTERN_HEX = Pattern.compile("0x[0-9a-fA-F]+");

    public PatternTools() {
    }

    public void addPattern(Context context, CodeView codeView) {
        //View Background monokia pro black
        codeView.setBackgroundColor(codeView.getResources().getColor(R.color.transparant));

        //Syntax Colors
        codeView.addSyntaxPattern(PATTERN_HEX, context.getResources().getColor(R.color.monokia_pro_purple));
        codeView.addSyntaxPattern(PATTERN_CHAR, context.getResources().getColor(R.color.monokia_pro_green));
        codeView.addSyntaxPattern(PATTERN_STRING, context.getResources().getColor(R.color.orange2));
        codeView.addSyntaxPattern(PATTERN_NUMBERS, context.getResources().getColor(R.color.monokia_pro_purple));
        codeView.addSyntaxPattern(PATTERN_KEYWORDS, context.getResources().getColor(R.color.monokia_pro_pink));
        codeView.addSyntaxPattern(PATTERN_BUILTINS, context.getResources().getColor(R.color.monokia_pro_pink));
        codeView.addSyntaxPattern(PATTERN_COMMENT, context.getResources().getColor(R.color.monokia_pro_grey));
        codeView.addSyntaxPattern(PATTERN_ANNOTATION, context.getResources().getColor(R.color.monokia_pro_pink));
        codeView.addSyntaxPattern(PATTERN_ATTRIBUTE, context.getResources().getColor(R.color.green));
        codeView.addSyntaxPattern(PATTERN_GENERIC, context.getResources().getColor(R.color.monokia_pro_pink));
        codeView.addSyntaxPattern(PATTERN_OPERATION, context.getResources().getColor(R.color.monokia_pro_pink));
        //Default Color
        codeView.setTextColor(context.getResources().getColor(R.color.monokia_pro_black));

        codeView.addSyntaxPattern(PATTERN_TODO_COMMENT, context.getResources().getColor(R.color.gold));

        codeView.reHighlightSyntax();
    }
}

this how I use the pattern class

        codeView.setFocusable(false);
        codeView.setEnableLineNumber(false);
        codeView.setVerticalScrollBarEnabled(false);

        codeView.setTabLength(4);
        codeView.setEnableAutoIndentation(true);

        // If I remove this, it works on android i modified
        new PatternTools().addPattern(this, codeView);

        codeView.setText(code);
        codeView.setHighlightWhileTextChanging(false);

For information, I’m completely sure, android that I modified is also version 5.1.1

I’m just afraid when publish my app, other android 5.1.1 will have the same problem

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
SasmitaNovitasaricommented, Mar 29, 2022

@AmrDeveloper

IT’S WORK-!!

I recently realized that this error also occurs on my android 11 and other android 5.1.1 . But it still can run normally

After using your latest example they are gone. Included in android 11 and my other android 5.1.1

Thank you so much

0reactions
AmrDevelopercommented, Mar 29, 2022

@SasmitaNovitasari

That’s great news, you are welcome,

Enjoy CodeView 👍🏻

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed to inflate ColorStateList, leaving it to the framework java ...
So, I have finished with this solution that works for me. To TextInputLayout add this string app:errorTextAppearance="@style/MyAppTheme.
Read more >
"Failed to inflate ColorStateList" when showing setup wizard
"Failed to inflate ColorStateList" when showing setup wizard ... Failed to inflate ColorStateList, leaving it to the framework java.lang.
Read more >
[Solved]-Getting "Failed to inflate ColorStateList, leaving it to ...
Coding example for the question Getting "Failed to inflate ColorStateList, leaving it to the framework" when using ShapeableImageView-kotlin.
Read more >
ShapeableImageView Failed to inflate ColorStateList, leaving ...
运行程序报以上的错误。 解决: 加上一个strokeColor属性即可。
Read more >
Can't convert to color: type=0x2 In TextInputLayout
09-26 17:46:04.650 19427-19427/com.ifreecomm.mst E/AppCompatResources: Failed to inflate ColorStateList, leaving it to the framework java.lang.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found