Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Matcher replaceAll()  RSS feed

 
Randall Twede
Ranch Hand
Posts: 4583
6
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as far as i can see my code is exactly like the tutorial except i use the other Pattern constructor
it compiles but i get a NullPointerException at Matcher.getTextLength(unknown source)
the tutorial:

my code:
 
Andrea Binello
Ranch Hand
Posts: 47
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randall Twede wrote:as far as i can see my code is exactly like the tutorial except i use the other Pattern constructor
it compiles but i get a NullPointerException at Matcher.getTextLength(unknown source)

My first impression is that text is null. getText() of Swing text components can return a null (see documentation) ... why you are eventually in this situation ... I don't know without seeing the rest of the code.
 
Randall Twede
Ranch Hand
Posts: 4583
6
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are correct Andrea. it is null and no doubt for the reason mentioned in the API. it turns out the problem is not this code. it only throws the exception if the text comes from an rtf file. it works with plain text and html pages. there are other problems involving rtf as well. i will see what i can find out and if i need more help i will post a different thread.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!