【发布时间】:2014-08-03 03:14:18
【问题描述】:
为什么总是返回 -1? 这与'@'作为注释符号有什么关系吗?
如何搜索第一次出现的以“@”开头的子字符串?
UserMentionEntity[] userMentionEntities = status.getUserMentionEntities();
for (UserMentionEntity ume : userMentionEntities) {
final String mention = ume.getText();
int mentionStart = text.indexOf("@" + mention);
int mentionEnd = mentionStart + mention.length();
ss.setSpan(new ForegroundColorSpan(Color.parseColor(COLOR)), mentionStart, mentionEnd + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
显然,mentionStart 是 -1。 我正在使用 twitter4j 库。
示例:
text: RT @Cornerstone_TMC Thank you @ukgdos at sa lahat ng nag-abang kanina kay @yengpluggedin! #SeenZoned @academyofrocksg… http://t.co/rsLqjlZJgg
mention: ukgdos
【问题讨论】:
-
text的值是多少?mention的值是多少? -
发布样本和预期结果。
-
我收到来自公开个人资料的推文。没什么特别的。像这样:“穿着@snh_fashion 平底鞋。????fb.me/3CustlXWH”
-
@user3903214 谢谢。现在你有一个正确的问题。
-
java.lang.IndexOutOfBoundsException: setSpan (-1 ... 6) 在 0 之前开始
标签: java android twitter4j indexoutofboundsexception indexof