MaterialSpinner icon indicating copy to clipboard operation
MaterialSpinner copied to clipboard

llegalArgumentException when setting error message

Open DCampodonico opened this issue 6 years ago • 7 comments

I'm getting this exception if I set an error message in onCreate:

E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.IllegalArgumentException: Layout: -168 < 0
        at android.text.Layout.<init>(Layout.java:215)
        at android.text.StaticLayout.<init>(StaticLayout.java:493)
        at android.text.StaticLayout.<init>(StaticLayout.java:479)
        at android.text.StaticLayout.<init>(StaticLayout.java:457)
        at android.text.StaticLayout.<init>(StaticLayout.java:437)
        at fr.ganfra.materialspinner.MaterialSpinner.prepareBottomPadding(MaterialSpinner.java:380)
        at fr.ganfra.materialspinner.MaterialSpinner.setError(MaterialSpinner.java:760)

Maybe this is happening because the view wasn't completely laid out when calling setError(). A simple workaround is to delay the setError() by some milliseconds, but I don't know how reliable this is on older devices or if it will work everytime.

DCampodonico avatar Feb 08 '18 02:02 DCampodonico

same error

chim0380 avatar Oct 30 '18 08:10 chim0380

I also have been getting this error for sometime.

henriquecm avatar Jan 23 '19 15:01 henriquecm

I am also facing same issue many times. on android os 8.1

kalesonali avatar Jun 11 '19 05:06 kalesonali

Hi you can try with this lib: https://github.com/Chivorns/SmartMaterialSpinner The problem already fixed in this lib. Good luck.

Chivorns avatar Jun 20 '19 03:06 Chivorns

Still having this issue

novas1r1 avatar Aug 06 '19 12:08 novas1r1

This error can occur when setError() is called during a lifecycle Activity/Fragment , rather than a user action. For example if you call setError onStart, on Resume. Spinner can't draw and measure correctly. I solved this error by calling setError in handler.postDelayed()

chim0380 avatar Aug 06 '19 12:08 chim0380

Hi @novas1r1 , have you tried https://github.com/Chivorns/SmartMaterialSpinner yet?

Chivorns avatar Aug 13 '19 07:08 Chivorns