Skip to content

Failed to inflate ColorStateList, leaving it to the framework #23

Open
@sasmitadn

Description

@sasmitadn

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions