wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes <identifier> expected problem - Vectors. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

<identifier> expected problem - Vectors.

Yun Lee
Greenhorn

Joined: Mar 11, 2010
Posts: 6
Hello everyone, please help, I have been trying for 3 hours and can't solve this. The problem is in the bold part and now I get an <identifier> expected problem, I've tried clone and just about everything but can't get it to work...

import java.io.*;
import javax.swing.*;
import java.util.Vector;

public class Teams
{
//instance vars
private Vector<Vector <Object>> team1;
private Vector<Vector <Object>> team2;
private Vector<Vector <Object>> team3;
private Vector<Vector <Object>> team4;

public Teams()
{
team1 = new Vector<Vector <Object>>();
team2 = new Vector<Vector <Object>>();
team3 = new Vector<Vector <Object>>();
team4 = new Vector<Vector <Object>>();

FileRead("team1.txt", team1);
FileRead("team2.txt", team2);
FileRead("team3.txt", team3);
FileRead("team4.txt", team4);

initialiseTeams(team1);
}

public void FileRead(String fileName, Vector teamVector)
{
try
{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream(fileName);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By line
//int counter = 0;
while ((strLine = br.readLine()) != null)
{
Vector<Object> v = new Vector<Object>();
teamVector.addElement(v);
String[] values = strLine.split(",");
for (String str : values)
{
v.addElement(str);
// System.out.println(str);
}
v.trimToSize();
teamVector.trimToSize();
}
//Close the input stream
in.close();
}
catch (Exception e)
{
//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}

public void initialiseTeams(Vector teamVector)
{
Vector v = tV.elementAt(0).clone();
Defender def1 = new Defender(teamVector.get(1).(get(0)), teamVector.get(1).(get(1)), teamVector.get(1).(get(2)), teamVector.get(1).(get(3)), teamVector.get(1).(get(4)));
Defender df2 = new Defender(teamVector.get(2).get(0), teamVector.get(2).get(1), teamVector.get(2).get(2), teamVector.get(2).get(3), teamVector.get(2).get(4));

}

}

I am trying to initialise the intgers and strings in the vectors so that I can utilise them in a GUI in a separate class. The vector material are in a separate .txt file.

In the bold part: the "teamVector.get(1)" works, but the .(get(0)) part at the end of each one is causing the problem. How can I get round this?

thanks ever so much!
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2850
    
  11

something.(get(0)) is never correct syntax. Try teamVector.get(1).get(0).

I'm not a big fan of the Vector class, and definitely not a Vector of Vectors, but that change should at least let you compile.
Yun Lee
Greenhorn

Joined: Mar 11, 2010
Posts: 6
no I have changed it to;

new Defender(teamVector.get(2).get(0), teamVector.get(2).get(1), teamVector.get(2).get(2), teamVector.get(2).get(3), teamVector.get(2).get(4));

but still no luck... still get the same error and won't let me compile...

thanks... please help!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: <identifier> expected problem - Vectors.