以下代码在Android4上运行良好,但在Android2中会导致IllegalArgumentException。
有什么线索吗?
Locale currentLocale = new Locale("en_UK");
final BreakIterator boundary = BreakIterator.getSentenceInstance(currentLocale);
boundary.setText("a");
int thisThrowsExceptionInVersion2 = boundary.preceding(1);例外:
08-08 22:29:14.414: E/AndroidRuntime(329): Caused by: java.lang.IllegalArgumentException
08-08 22:29:14.414: E/AndroidRuntime(329): at java.text.RuleBasedBreakIterator.validateOffset(RuleBasedBreakIterator.java:74)
08-08 22:29:14.414: E/AndroidRuntime(329): at java.text.RuleBasedBreakIterator.preceding(RuleBasedBreakIterator.java:158)
08-08 22:29:14.414: E/AndroidRuntime(329): at kalle.palle.namespace.KallePalleActivity.onCreate(KallePalleActivity.java:26)发布于 2012-08-14 01:19:52
下面是姜饼代码中的validateOffset
private void validateOffset(int offset) {
CharacterIterator it = wrapped.getText();
if (offset < it.getBeginIndex() || offset >= it.getEndIndex()) {
throw new IllegalArgumentException();
}
}在ICS中的代码如下
private void validateOffset(int offset) {
CharacterIterator it = wrapped.getText();
if (offset < it.getBeginIndex() || offset > it.getEndIndex()) {
String message = "Valid range is [" + it.getBeginIndex() + " " + it.getEndIndex() + "]";
throw new IllegalArgumentException(message);
}
}>=已更改为>。2.X设备中的结束偏移量检查似乎是错误的。在传递给preceding的偏移量与字符串的结束索引重叠的情况下,尤其如此。这似乎是框架中的错误。
您可以在libcore/luni/src/main/java/java/text/RuleBasedBreakIterator.java.的AOSP代码中找到源代码。
这是Gingerbread code,这是ICS code
https://stackoverflow.com/questions/11872758
复制相似问题