Scala on Android: java.lang.NoSuchMethodError: java.lang.String.isEmpty
Asked Answered
B

4

7

I am getting following Exception on Android 2.2.1:

java.lang.NoSuchMethodError: java.lang.String.isEmpty

I am calling text.isEmpty from Scala. Any idea, how to solve this?

Backcross answered 9/12, 2010 at 9:52 Comment(1)
check this post #7568265Glanders
A
9

Use JRE/JDK 1.5, which did not have an isEmpty method on String. This will avoid situations where Scala uses 1.6's isEmpty instead of its own. If you have Java libraries as well, be sure to pick ones compatible with 1.5.

Adhesive answered 9/12, 2010 at 11:1 Comment(0)
F
10

java.lang.String.isEmpty() was added in Gingerbread (2.3). You will have to write your own replacement function...

Frilling answered 9/12, 2010 at 10:2 Comment(3)
I am compiling against 2.2 and compiler compiles that. It finds isEmpty implementation in IndexedSeqOptimized.isEmpty.Backcross
That's some Scala weirdism. The Android API in your question definitely didn't appear until Gingerbread. See that developer.android.com/reference/java/lang/String.html#isEmpty() says "Since API Level 9"Frilling
Yes, but I think it should use the implementation from the trait IndexedSeqOptimized. The question is, why it is not using this trait?Backcross
A
9

Use JRE/JDK 1.5, which did not have an isEmpty method on String. This will avoid situations where Scala uses 1.6's isEmpty instead of its own. If you have Java libraries as well, be sure to pick ones compatible with 1.5.

Adhesive answered 9/12, 2010 at 11:1 Comment(0)
N
7

Alternativly use (text.length()>0) ?

Narcose answered 9/12, 2010 at 10:5 Comment(1)
Yes, I am using now text.length == 0.Backcross
H
4

Use TextUtils.isEmpty() instead, available since API level 1.

Headgear answered 14/3, 2013 at 13:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.