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(JPearReaderTest.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-)
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
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