For Programmers: Free Programming Magazines  


Home > Archive > Java Help > December 2006 > StringTokenizer in 1.6









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author StringTokenizer in 1.6
IchBin

2006-12-21, 7:08 pm

Just tried to run a program that uses StringTokenizer in JDK 1.6.0 but
it fails with NoSuchElementException and Unknown Source for nextToken().
I can get around it by using string.split().

Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(Unknown Source)
at
weconsultants.org.JPear.JPearReaderTest.getTokens(JPearReaderTest.java:249)
at
weconsultants.org.JPear.JPearReaderTest. buildDataInstalledPackages(JPearReaderTe
st.java:218)
at
weconsultants.org.JPear.JPearReaderTest.processNetStat(JPearReaderTest.java:153)
at
weconsultants.org.JPear.JPearReaderTest.buildPanel(JPearReaderTest.java:119)
at weconsultants.org.JPear.JPearReaderTest.main(JPearReaderTest.java:103)


It was just unexpected. Has anyone have a problem with this?

Example

private static List getTokens(String inTargetLine)
{
List list = new LinkedList(); // Doubly-linked list
list = new ArrayList(); // List implemented as growable
array

StringTokenizer st = new StringTokenizer(inTargetLine);
while (st.hasMoreTokens())
{
list.add(st.nextToken());
}
return list;
}

--
Thanks in Advance... http://ichbin.9999mb.com
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
________________________________________
______________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
hiwa

2006-12-22, 4:12 am

IchBin wrote:
> Just tried to run a program that uses StringTokenizer in JDK 1.6.0 but
> it fails with NoSuchElementException and Unknown Source for nextToken().
> I can get around it by using string.split().
>
> Exception in thread "main" java.util.NoSuchElementException
> at java.util.StringTokenizer.nextToken(Unknown Source)
> at
> weconsultants.org.JPear.JPearReaderTest.getTokens(JPearReaderTest.java:249)
> at
> weconsultants.org.JPear.JPearReaderTest. buildDataInstalledPackages(JPearReaderTe
st.java:218)
> at
> weconsultants.org.JPear.JPearReaderTest.processNetStat(JPearReaderTest.java:153)
> at
> weconsultants.org.JPear.JPearReaderTest.buildPanel(JPearReaderTest.java:119)
> at weconsultants.org.JPear.JPearReaderTest.main(JPearReaderTest.java:103)
>
>
> It was just unexpected. Has anyone have a problem with this?
>
> Example
>
> private static List getTokens(String inTargetLine)
> {
> List list = new LinkedList(); // Doubly-linked list
> list = new ArrayList(); // List implemented as growable
> array
>
> StringTokenizer st = new StringTokenizer(inTargetLine);
> while (st.hasMoreTokens())
> {
> list.add(st.nextToken());
> }
> return list;
> }
>
> --
> Thanks in Advance... http://ichbin.9999mb.com
> IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
> ________________________________________
______________________________
> 'If there is one, Knowledge is the "Fountain of Youth"'
> -William E. Taylor, Regular Guy (1952-)

I get no error nor exception.
Your method just works fine for a space delimited string.

Oliver Wong

2006-12-22, 7:09 pm


"hiwa" <HGA03630@nifty.ne.jp> wrote in message
news:1166778876.318170.272550@80g2000cwy.googlegroups.com...
> IchBin wrote:
[...][color=darkred]
> I get no error nor exception.
> Your method just works fine for a space delimited string.


IchBin, maybe you can post an SSCCE demonstrating the problem. Or at
least, give us the value for "inTargetLine" which causes the exception.
Maybe you're using some strange Unicode value which is confusing the
StringTokenizer (which has apparently been deprecated)?

- Oliver


IchBin

2006-12-22, 7:09 pm

Oliver Wong wrote:
> "hiwa" <HGA03630@nifty.ne.jp> wrote in message
> news:1166778876.318170.272550@80g2000cwy.googlegroups.com...
[snip code][color=darkred]
> [...]
>
> IchBin, maybe you can post an SSCCE demonstrating the problem. Or at
> least, give us the value for "inTargetLine" which causes the exception.
> Maybe you're using some strange Unicode value which is confusing the
> StringTokenizer (which has apparently been deprecated)?
>
> - Oliver
>
>


Thanks hiwa and Oliver. Yea, I remember about three year ago Sun
mentioned it wanted people to use string.split and get away from
StringTokenizer. Sorry, can't reason why I used StringTokenizer. I
rewrote to use string.split(). I am more concerned with my 1.6 install
if I am getting this error. I was not getting this error before. I
rebooted my machine and ran a test ala SSCCE. Here is the result:

<SSCCE>
public class problem
{
public static void main(String[] args)
{
List <String>list = new ArrayList<String>();
list = getTokens("1 22 3333 4444 55555");
}
private static List getTokens(String inTarget)
{
List <String>list = new ArrayList<String>();
StringTokenizer st = new StringTokenizer(inTarget);
while (st.hasMoreTokens())
{
System.out.println(st.nextToken());
list.add(st.nextToken());
}
return list;
}
}
</SSCCE>

<output>
C:\Program Files\Java\jdk1.6.0\bin\java.exe -classpath "C:\Program
Files\Java\jdk1.6.0\lib\tools.jar;C:\Program
Files\Java\jdk1.6.0\lib\dt.jar;C:\Program
Files\Java\jre1.6.0\lib\rt.jar;C:\Documents and Settings\Ed Taylor\My
Documents\My Java Workarea" problem
1
3333
55555
Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(StringTokenizer.java:332)
at problem.getTokens(problem.java:19)
at problem.main(problem.java:10)
Finished executing
</output>

--
Thanks in Advance... http://ichbin.9999mb.com
IchBin, Pocono Lake, Pa, USA
________________________________________
______________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
IchBin

2006-12-22, 7:09 pm

Oliver Wong wrote:
> "hiwa" <HGA03630@nifty.ne.jp> wrote in message
> news:1166778876.318170.272550@80g2000cwy.googlegroups.com...
[snip code][color=darkred]
> [...]
>
> IchBin, maybe you can post an SSCCE demonstrating the problem. Or at
> least, give us the value for "inTargetLine" which causes the exception.
> Maybe you're using some strange Unicode value which is confusing the
> StringTokenizer (which has apparently been deprecated)?
>
> - Oliver
>
>


Thanks hiwa and Oliver. Yea, I remember about three year ago Sun
mentioned it wanted people to use string.split and get away from
StringTokenizer. I changed to use string.split(). Sorry, can't reason
why I used StringTokenizer. Lapse in old habits I guess.

Today I was getting weird storage errors with the java vm under Eclipse.
So I rebooted my pc and all seems ok as I wipe the sweat off my brow..
lol. I was worried about my 1.6 install. Sorry and thanks for your help.

--
Thanks in Advance... http://ichbin.9999mb.com
IchBin, Pocono Lake, Pa, USA
________________________________________
______________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com