Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SasmitaNovitasari opened this issue Mar 26, 2022 · 6 comments
Open
Labels
question Further information is requested

Comments

@SasmitaNovitasari
Copy link

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

@AmrDeveloper
Copy link
Owner

Hello @SasmitaNovitasari.

The exception stack trace show some positions from verticalstepperform library so the problem maybe from it,

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)

Can you please run codeview example and verticalstepperform on your custom ROM so we can detect the problem, also i will try to run this code in many emulators and try to find the error

@SasmitaNovitasari
Copy link
Author

@AmrDeveloper
Thanks for reply

Maybe they not suitable or something. This error only happend in my custom rom, I will try just use codeview without verticalStepper library next time and I will edit this for the result

@SasmitaNovitasari
Copy link
Author

@AmrDeveloper

I already try use codeView in mainActivity without any third-library. Still have same problem in my custom ROM. That's mean the problem from this library.

same as yesterday, codeView work if I'm not add pattern color

@AmrDeveloper
Copy link
Owner

@SasmitaNovitasari I tested the example app on Emulator with version 5.1,

The problem is that Old Android versions didn't support regex named group so i updated the example app regex, and removed the commit regex,

https://stackoverflow.com/questions/32776168/regex-pattern-in-android-studio-throws-error-this-named-group-syntax-is-not-su

So can you try to pull the updates and run the example app again so we can check if it work on your custom ROM

@SasmitaNovitasari
Copy link
Author

@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

@AmrDeveloper
Copy link
Owner

@SasmitaNovitasari

That's great news, you are welcome,

Enjoy CodeView 👍🏻

@AmrDeveloper AmrDeveloper added the question Further information is requested label Sep 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants