No such method error while setting text appearance

2.4k views Asked by At

I'm using the following code to change the font size to medium or high or small. getFontSize() will return any of these sizes

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
     holder.title.setTextAppearance(new AppController().getFontSize());
 else
     holder.title.setTextAppearance(mContext, new AppController().getFontSize());

But im getting the following error:

java.lang.NoSuchMethodError: No virtual method setTextAppearance(I)V in class Landroid/widget/TextView; or its super classes (declaration of 'android.widget.TextView' appears in /system/framework/framework.jar)

Why am I getting such error?

1

There are 1 answers

3
dev.bmax On BEST ANSWER

TextView::setTextAppearance expects an integer value, that identifies a style resource in the project (like @android:style/TextAppearance.Material.Body1). If this is your intention, then make sure, that your getFontSize() method returns a valid ID.

But, I guess, that you a actually trying to set the font size, which should be done using the setTextSize(float size) method of TextView.