Reading from an Array ==Tokenizer

A

Andy K

Would you please help ne. I am trying to read from an array but I keep
getting an error (Variable not defined. here is the piece of code please
help.
{StringTokenizer tokens;

tokens = new StringTokenizer(textLiner)
teamName = tokens.nextToken();
points = Integer.parsInt(tokens.nextToken());

premiership t[] = new Premiership[20];
int i;
for (i=0; i<t.length;i++);
{
t = new Premiership(teamname,points);
t.teamName = teamName;
t.points = points;
}
 
M

Michael Borgwardt

Andy said:
Would you please help ne. I am trying to read from an array but I keep
getting an error (Variable not defined. here is the piece of code please
help.
teamName = tokens.nextToken();
points = Integer.parsInt(tokens.nextToken());

Of course you have to put these lines INSIDE the loop!
Furthermore, it assumes that your data is all on one line
and contains syntax errors.
 
A

Andy K

What are the sytax errors in these lines then? I though by putting a ; I
am saying this is a new line.
 
M

Michael Borgwardt

Andy said:
What are the sytax errors in these lines then?

It's "parseInt", not "parsInt".
I though by putting a ; I
am saying this is a new line.

In Java code it marks the end of a statement. What I meant is that the
*data* you're reading with the StringTokenizer must be on one line
for your code to work, team name and points alternating and separated by
the separator in "textLiner".
If each entry is on its own line (no ; necessary), which I suspect it is,
you need to read the line and create the StringTokenizer inside the loop
as well.
 
A

Andy K

Thanks for your help Michael I forgot to put the loop. I alread have the
loop in my code and it looks like this:

Something up here


textLine = fileInput.readLine();
moreToRead = (textLine != null);

while (moreToRead)
{
tokens = new StringTokenizer(textLiner)
teamName = tokens.nextToken();
points = Integer.parsInt(tokens.nextToken());

premiership t[] = new Premiership[20];
int i;
for (i=0; i<t.length;i++);
{
t = new Premiership(teamname,points);
t.teamName = teamName;
t.points = points;
}

At the moment I cant even run it yet o check it its reading properly
since I have to compile it

Please help . thanks in advance
 
J

Joe Smith

teamName = tokens.nextToken();
[...]
t = new Premiership(teamname,points);


Shouldn't this one be "teamName"?
t.teamName = teamName;
t.points = points;


You probably won't be needing these two instructions, as your constructor
is -I guess- doing this already.
 
J

John C. Bollinger

Andy said:
Would you please help ne. I am trying to read from an array but I keep
getting an error (Variable not defined. here is the piece of code please
help.
{StringTokenizer tokens;

tokens = new StringTokenizer(textLiner)
teamName = tokens.nextToken();
points = Integer.parsInt(tokens.nextToken());

premiership t[] = new Premiership[20];
int i;
for (i=0; i<t.length;i++);
{
t = new Premiership(teamname,points);
t.teamName = teamName;
t.points = points;
}



If you posted (or read) the full error message, it would tell us (or
you) _which_ variable is not defined. Presumably it is "textLiner".
Depending on the definition of the Premiership class, it might also be
Premiership.teamName or Premiership.points.


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top