2

Android M has changed the setters for StaticLayout and instead we have the Builder pattern. But with the following code:

StaticLayout staticLayout = StaticLayout.Builder.obtain("Hello", 0, "Hello".length(), getTextPaint(), 100).build();

I get the following exception:

Process: sharpdevs.com.legalapp, PID: 7695 java.lang.NoClassDefFoundError: Failed resolution of: Landroid/text/StaticLayout$Builder;

I've tried everything, could this be an Android bug or am I missing a support library dependency?

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
stefdev777
  • 419
  • 5
  • 15
  • 2
    This may sound a little obvious, but are you sure you're running the code on an Android M/6.0 device? – MH. Sep 17 '15 at 18:24
  • You're right, I don't know how I missed the obvious, thought I was running an API 23 emulator. – stefdev777 Sep 17 '15 at 20:00

1 Answers1

1

It looks like this questions has already been solved in the comments, so to add it as an actual answer...

StaticLayout.Builder was added in API 23, so trying to run it on an earlier API will cause an exception. You can use the standard StaticLayout constructors for earlier API versions.

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393