This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Regular Expression pattern search is throwing "java.lang.IllegalStateException"  RSS feed

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to find the position of string that matches the regular expression in a given 'word'. But for some reason I get the following Exception.

Exception in thread "main" java.lang.IllegalStateException: No match available
at java.util.regex.Matcher.start(Matcher.java:325)
at myworkspace.TestRegEx.<init>(TestRegEx.java:16)
at myworkspace.TestRegEx.main(TestRegEx.java:21)

I have created a small program that demonstrates the problem, posted below. I would really appreciate some input on this. thanks

 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll have better luck if you post your actual code, so that the line numbers in the exception line up with the line numbers posted.

This may mean you'll have to create a separate, smaller program just to demonstrate the problem.


Also, have you tried looking at the docs for Matcher.start(), to understand how to use it correctly, and to see why it might throw that exception? That's generally the best place to start.

 
Poorav Chaudhari
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I realized I needed to call the matcher.match() or the matcher.find() method before calling matcher.start().
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!