Skip to content
Advertisement

Java.lang.UnsupportedOperationException Android Studio

My app keeps on crashing on launch because of several errors.

  1. java.lang.InvocationTargetException
  2. java.lang.UnsupportedOperationException

Here is the logcat error for the second exception.

Caused by: java.lang.UnsupportedOperationException: Can't convert to ComplexColor: type=0x1
    at android.content.res.ResourcesImpl.loadComplexColorForCookie(ResourcesImpl.java:1137)
    at android.content.res.ResourcesImpl.loadComplexColorFromName(ResourcesImpl.java:1013)
    at android.content.res.ResourcesImpl.loadColorStateList(ResourcesImpl.java:1092)
    at android.content.res.Resources.loadColorStateList(Resources.java:1062)
    at android.content.res.TypedArray.getColorStateList(TypedArray.java:599)
    at android.widget.TextView.readTextAppearance(TextView.java:3961)
    at android.widget.TextView.<init>(TextView.java:1064)
    at android.widget.TextView.<init>(TextView.java:968)
    at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:108)
    at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:103)
    at com.example.moveapplication.utils.MAFTextViewBold.<init>(MAFTextViewBold.kt:8)
        ... 72 more

From the last line it says my error is from my MAFTextViewBold.kt file

class MAFTextViewBold (context: Context, attrs: AttributeSet) : AppCompatTextView(context, attrs){
init {
    applyFont()
}

private fun applyFont() {
    val typeface:Typeface =
        Typeface.createFromAsset(context.assets, "Montserrat-Bold.ttf")
    setTypeface(typeface)
}

}

What could be causing the error? It was compiling before but after I did a factory reset on Android Studio I could not ran my app. The erros started showing.

Advertisement

Answer

It turns out that the exceptions were brought by using a complex color that could not be translated. see the exception:

Caused by: java.lang.UnsupportedOperationException: Can't convert to ComplexColor: type=0x1


            

This color android:textColor="@color/aquamarine" can not be converted properly as applied in my MAFTextView class. Even on a normal TextView it still can’t be converted. I changed the color to black and my app was running again. Android Development always finds a way to amaze me. Just a color change throws two exceptions.smh

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement