NoSuchElementException using StringTokenizer
807603Jul 25 2005 — edited Dec 2 2007Hello:
I'm having problems with my code because I'm getting an exception while I try to assign the tokens of a file to specific variables. I don't see the mistake in the code, can you help me to detect the mistake. the code is bellow:
while((oneLine=br.readLine())!=null)
{
StringTokenizer st=new StringTokenizer(oneLine);
if(st.countTokens()!=2 && st.countTokens()!=3)
{
System.err.println("Skipping bad line " + oneLine);
continue;
}
String token1=st.nextToken();
String token2=st.nextToken();
int rows=Integer.parseInt(token1);
int columns=Integer.parseInt(token2);
while(st.hasMoreTokens())
{
token1=st.nextToken();
token2=st.nextToken(); //NoSuchElementException
String wall=st.nextToken();
int row, column;
int token_3=Integer.parseInt(token1)
if(token_3<rows)
row=token_3;
int token_4=Integer.parseInt(token2);
if(token_4<columns)
column=token_4;
Position current=new Position(token_3,token_4, wall);
int[][] theMaze= new int [rows][columns];
Position end=new Position(rows-1, columns-1, wall);
}
}
}
The error is:
Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(StringTokenizer.java:332)
at Position.main(Position.java:252)
Thanks in anticipation