JakeWharton/ViewPagerIndicator

Crash when using color values from styles.

dmitvitalii opened this issue ยท 15 comments

I'm trying to set colors like that:

app:fillColor="?attr/colorAccent"
app:pageColor="?attr/colorPrimary"
app:strokeColor="?attr/colorPrimary"

It worked before, but now it throws:

android.view.InflateException: Binary XML file line #16: Binary XML file line #17: Error inflating class com.viewpagerindicator.CirclePageIndicator
caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1d

I've tried to set @color/color_primary values and '#ff00ff' color hex values: the same issue.

As a workaround: I set all needed colors in runtime by calling setFillColor(), setPageColor() and setStrokeColor() respectively.

minSdkVersion 21
targetSdkVersion 26
buildToolsVersion "26.0.0"

I have the same issue. It happened when I upgraded Gradle plugin to 3.0.0-beta4

Same here after updating project to new Android Plugin.

Same here after updating to Android Studio 3 RC1, Gradle 4, Android Gradle plugin 3 rc2

@janbolat same here too

toXel commented

Does anyone know a good alternative to this library? As it is no longer maintained I don't think we will get a fix for this anytime soon...

Same too.
My solution is how it say dmitvitalii, removing --> app:fillColor="@color/blue"
and set it programmatically mIndicator.setFillColor(ContextCompat.getColor(context, R.color.blue));

This Stackoverflow Answer worked well for me: https://stackoverflow.com/a/46950028/1350902

In my case, I had to set all app: attributes programmatically

@jannisveerkamp question please,
did you added something else than: compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1' ?

because I'm getting an error

Error:(80, 13) Failed to resolve: com.github.JakeWharton:ViewPagerIndicator:2.4.1

This is probably JitPack syntax
compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
you should add JitPack repository

repositories {
    maven { url "https://jitpack.io" }
}

but in my case it caused error somewhere else, so I solved this by setting the style programatically

thank you @kotucz adding jitpack.io worked!

compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1' using jitpack.io didn't work for me with the android gradle plugin 3.0.

Instead I had to set programmatically all the view attributes that I previously set in the xml layout with cpi: (or app:) attributes.

Example

<com.viewpagerindicator.CirclePageIndicator
    cpi:fillColor="@color/azure"
    cpi:pageColor="@color/white"
    cpi:radius="4dp"
    cpi:snap="true"
    cpi:strokeWidth="0dp" />

I removed all the cpi: attributes and set them all programmatically:

circlePageIndicator.setFillColor(ContextCompat.getColor(getContext(), R.color.azure));
circlePageIndicator.setPageColor(ContextCompat.getColor(getContext(), R.color.white));
circlePageIndicator.setRadius((int) (4 * Resources.getSystem().getDisplayMetrics().density));
circlePageIndicator.setSnap(true);
circlePageIndicator.setStrokeWidth(0);

See also https://stackoverflow.com/a/47163075/885464

I get an exception on Android 7.1.1 :

java.lang.UnsupportedOperationException: Can't convert value at index 5 to color: type=0x5
                                                                      at android.content.res.TypedArray.getColor(TypedArray.java:463)
                                                                      at com.viewpagerindicator.CirclePageIndicator.<init>(CirclePageIndicator.java:96)
                                                                      at com.viewpagerindicator.CirclePageIndicator.<init>(CirclePageIndicator.java:72)
                                                                      at java.lang.reflect.Constructor.newInstance0(Native Methodat java.lang.reflect.Constructor.newInstance(Constructor.java:430at android.view.LayoutInflater.createView(LayoutInflater.java:645at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727at android.view.LayoutInflater.rInflate(LayoutInflater.java:858at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821at android.view.LayoutInflater.inflate(LayoutInflater.java:518at android.view.LayoutInflater.inflate(LayoutInflater.java:426at android.view.LayoutInflater.inflate(LayoutInflater.java:377at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139at com.sankuai.mhotel.GuideActivity.onCreate(GuideActivity.java:48at android.app.Activity.performCreate(Activity.java:6679at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726at android.app.ActivityThread.-wrap12(ActivityThread.javaat android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477at android.os.Handler.dispatchMessage(Handler.java:102at android.os.Looper.loop(Looper.java:154at android.app.ActivityThread.main(ActivityThread.java:6119at java.lang.reflect.Method.invoke(Native Methodat com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776

targetSdkVersion is 26
Is this a Compatibility problem?

@janbolat ๏ผŒ I have tried this before,it doesn't work for me.