android - How to resolve IndexOutOfBounds exception when using matcher.find()? -
my app stops if no match found. piece of code:
while (matcher.find()) { tagvalues.add(matcher.group(1)); } how can show user there no match , still on same page? logcat. gives indexoutofbounds exception.
java.lang.indexoutofboundsexception: invalid index 0, size 0 04-16 21:17:56.700: e/androidruntime(19492): @ java.util.arraylist.throwindexoutofboundsexception(arraylist.java:255) 04-16 21:17:56.700: e/androidruntime(19492): @ java.util.arraylist.get(arraylist.java:308) 04-16 21:17:56.700: e/androidruntime(19492): @ com.approve.smsapp.conversation$1.onitemclick(conversation.java:115) 04-16 21:17:56.700: e/androidruntime(19492): @ android.widget.adapterview.performitemclick(adapterview.java:299) 04-16 21:17:56.700: e/androidruntime(19492): @ android.widget.abslistview.performitemclick(abslistview.java:1113) 04-16 21:17:56.700: e/androidruntime(19492): @ android.widget.abslistview$performclick.run(abslistview.java:2904) 04-16 21:17:56.700: e/androidruntime(19492): @ android.widget.abslistview$3.run(abslistview.java:3638)
please add more code better understand problem. see below simple example of matcher, may you:
public class regextestpatternmatcher { public static final string example_test = "this small example string i'm going use pattern matching."; public static void main(string[] args) { pattern pattern = pattern.compile("\\w+"); // in case ignore case sensitivity, // use statement: // pattern pattern = pattern.compile("\\s+", pattern.case_insensitive); matcher matcher = pattern.matcher(example_test); // check occurance while (matcher.find()) { system.out.print("start index: " + matcher.start()); system.out.print(" end index: " + matcher.end() + " "); system.out.println(matcher.group()); } // create new pattern , matcher replace whitespace tabs pattern replace = pattern.compile("\\s+"); matcher matcher2 = replace.matcher(example_test); system.out.println(matcher2.replaceall("\t")); } }
Comments
Post a Comment