The string in the my stringTokenizer blows ups with error "java.util.NoSuchElementException" I see that in my stringTokenizer, it contains only part of the string, it does no show the comma (,) that is in the string. Part of the stringTokenizer contains a a fullname (one field) "lastName, firstName". So it looks like it blows up when it reaches the comma. I cannot strip the comma off of a fullname field otherwise when querieing against the database it will not find it without the comma. Can I use some kind of "escape sequence" for the comma in the stringTokenizer to prevent it from blowing up? If so, how? Thanks.
I assume that you are tokenizing your "lastname, firstname" string with the delimiter "," yes? In which case you probably won't see the comma because it is a token, not an element. For example:
would create a tokenizer containing two elements ("lastname", " firstname") and one token (",").
A quick glance at the JavaDoc for StringTokenizer and you discover that the possible causes of a NoSuchElementException being thrown is is there are no more tokens in a tokenizers string. This code will throw that exception:
If you are accessing the contents of a StringTokenizer, make sure you access them in a safe way, e.g.:
OK I follow now. The string you are tokenizing is "lastname, firstname" yes? And you are tokinizing on the delimiter "|" which doesn't feature in the string so you have a one element tokenizer with no tokens. Whatever, there are still only two ways to throw a NoSuchElementException, either by calling tokenizer.nextToken() or tokenizer.nextElement() when there are no more elements or tokens in the tokenize.
Perhaps you could post some code so we can see what's going on.
Linda M Wilson
Joined: May 27, 2004
stringTokenizer = new StringTokenizer(strContactedInfo, Constants.DELIMITER_PIPE);
fullname gets passed into strContactedInfo
I think the comma can be replaced with a different character for example a tilde?
Well you could replace the comma, and its not that difficult. But once again I'll have to say that is with 100% centainty not what is causing the NoSuchElementException.
Presuming you are passing in "lastname, firstname" into your tokenizer and you are delimiting it with a "|" character (I have no idea whether your Constants class actually defines the DELIMITER_PIPE as a literal string "|"), then you will get a tokenizer with one element and no tokens in it. The element will be: "lastname, firstname". And the only way to get a NoSuchElementException is by calling nextElement() or nextToken() on this tokenizer in an unsafe way.
[ May 27, 2004: Message edited by: Paul Sturrock ] [ May 27, 2004: Message edited by: Paul Sturrock ]