![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
Vector Problem
Am using the vector method to read from my file, but i cant get it working, This is the error that am getting, the project is based on 5 separate java classes, all complies fine except this one, i will upload the code for this file(testDriver.java)
Thanks in advance. testDriver.java:45: cannot resolve symbol
symbol : variable Vector
location: class testDriver
Vector <String> lines = new Vector();
^
testDriver.java:45: cannot resolve symbol
symbol : variable String
location: class testDriver
Vector <String> lines = new Vector();
^
testDriver.java:45: cannot resolve symbol
symbol : variable lines
location: class testDriver
Vector <String> lines = new Vector();
^
testDriver.java:62: cannot resolve symbol
symbol : variable lines
location: class testDriver
lines.addElement(line);
^
testDriver.java:73: cannot resolve symbol
symbol : variable lines
location: class testDriver
return lines;
^
testDriver.java:80: cannot resolve symbol
symbol : constructor PrintStream (java.io.File)
location: class java.io.PrintStream
ps = new PrintStream (new File(fileout));
^
6 errorsimport java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.*;
import java.util.*;
import java.lang.*;
public class testDriver{
// Function to read a text file and return a vector with all the lines
String id="";
String first="";
String last="";
String code="";
String dept="";
String level;
String rate;
String ded;
String months;
String hrs;
String temp;
Database database = new Database();
PrintStream ps;
public Vector readFile (String filename )
{
Vector <String> lines = new Vector();
BufferedReader br = null;
try
{
br = new BufferedReader ( new FileReader( filename ) );
}
catch (FileNotFoundException e)
{
System.out.println("File: " + filename + " was not found.");
return null;
}
try
{
String line = br.readLine ();
while(line != null) {
lines.addElement(line);
line = br.readLine();
}
br.close();
} catch( IOException e) {
System.out.println("Error reading the file.");
return null;
}
return lines;
}
public void createDataFile(String fileout)
{
try
{
ps = new PrintStream (new File(fileout));
}
catch (FileNotFoundException e)
{
System.out.println("File was not found.");
}
}
public int readWord (String current, int i)
{
int j=i;
temp="";
while (((current.charAt(j))!=' ')&&((current.charAt(j))!='\n'))
{
temp += current.charAt(j);
j++;
}
//System.out.print(new String(temp)+" ");
return j;
}
public int ignoreSpace (String current, int j)
{
while ((current.charAt(j)) == ' ')
j++;
return j;
}
public void readEmployeeData (String current)
{
int k=0;
int m=0;
String tempStr[] = new String[11];
String tempstr="";
FullTimeEmployee tempEmp1;
PartTimeEmployee tempEmp2;
/*
//while ((current.charAt(k)) != '\n')
for (m=0; m<9; m++)
{
k = ignoreSpace(current, k);
k = readWord(current, tempstr, k);
tempStr[m] = ""+tempstr;
System.out.print (" "+String.valueOf(tempStr[m]));
//m++;
}
*/
k = ignoreSpace(current, k);
k = readWord(current, k);
id=temp;
System.out.println(""+id);
k = ignoreSpace(current, k);
k = readWord(current, k);
first = temp;
k = ignoreSpace(current, k);
k = readWord(current, k);
last = temp;
k = ignoreSpace(current, k);
k = readWord(current, k);
code = temp;
k = ignoreSpace(current, k);
k = readWord(current, k);
dept = temp;
k = ignoreSpace(current, k);
k = readWord(current, k);
level = temp;
k = ignoreSpace(current, k);
k = readWord(current, k);
rate = temp;
k = ignoreSpace(current, k);
k = readWord(current, k);
ded = temp;
k = ignoreSpace(current, k);
k = readWord(current, k);
months = temp;
k = ignoreSpace(current, k);
k = readWord(current, k);
hrs = temp;
/*
id = String.valueOf(tempStr[0]);
first = String.valueOf(tempStr[1]);
last = String.valueOf(tempStr[2]);
code = String.valueOf(tempStr[3]);
dept = String.valueOf(tempStr[4]);
level = String.valueOf(tempStr[5]);
rate = String.valueOf(tempStr[6]);
ded = String.valueOf(tempStr[7]);
months = String.valueOf(tempStr[8]);
//hrs = String.valueOf(tempStr[9]);
hrs = "13";
hrs = "13";
*/
if (code.equals("F"))
{
System.out.println("the F:"+code);
tempEmp1 = new FullTimeEmployee(id,first,last,dept,level,ded,months);
//tempEmp1 = new FullTimeEmployee(tempStr[0],tempStr[1],tempStr[2],tempStr[4],tempStr[5],tempStr[7],tempStr[8]);
database.addEmployeeData (tempEmp1);
}
else if (code.equals("P"))
{
System.out.println("the P:"+code);
//PartTimeEmployee tempEmp2;
tempEmp2 = new PartTimeEmployee(id,first,last,dept,rate,ded,hrs);
//tempEmp2 = new PartTimeEmployee(tempStr[0],tempStr[1],tempStr[2],tempStr[4],tempStr[6],tempStr[7],tempStr[9]);
database.addEmployeeData (tempEmp2);
}
}
/*****************************************************************************/
/** Creates a new instance of testDriver */
/*****************************************************************************/
public testDriver()
{
String filein = "input2.txt";
String fileout = "employeeInfo.txt";
String currentStr;
Vector lines = readFile(filein);
if(lines == null)
{
System.out.println("Cannot read file.");
return;
}
for (int j=0; j<lines.size(); j++)
{
currentStr = (String) lines.elementAt(j);
readEmployeeData (currentStr);
}
createDataFile(fileout);
database.printEmployeesData(ps);
}
public static void main(String args[])
{
new testDriver();
System.out.println("Yes!!!");
System.exit(0);
}
}
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
|
|
#2 |
|
Programmer
|
import java.util.Vector;
JD |
|
|
|
|
|
#3 | |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
Quote:
testDriver.java:48: cannot resolve symbol
symbol : variable Vector
location: class testDriver
Vector <String> lines = new Vector();
^
testDriver.java:48: cannot resolve symbol
symbol : variable String
location: class testDriver
Vector <String> lines = new Vector();
^
testDriver.java:48: cannot resolve symbol
symbol : variable lines
location: class testDriver
Vector <String> lines = new Vector();
^
testDriver.java:65: cannot resolve symbol
symbol : variable lines
location: class testDriver
lines.addElement(line);
^
testDriver.java:76: cannot resolve symbol
symbol : variable lines
location: class testDriver
return lines;
^
testDriver.java:83: cannot resolve symbol
symbol : constructor PrintStream (java.io.File)
location: class java.io.PrintStream
ps = new PrintStream (new File(fileout));
^
6 errors
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
|
|
|
#4 |
|
Expert Programmer
|
My guess is that you might not be using JDK 5.0, as previous versions don't support parameterized types (ie, Vector<String>). Try removing the space between Vector and <String>, so Vector <String> lines would be Vector<String> lines.
Also, to make your code more readable you can remove all the import statements and replace them with import java.io.*; import java.util.*;. Also, you appear to be missing a closing curly bracket on line 55. |
|
|
|
|
|
#5 |
|
Professional Programmer
|
1. Vector<String> myVector = new Vector<String>();
and 2. You should use ArrayList, Vector is deprecated. |
|
|
|
|
|
#6 |
|
Expert Programmer
|
Vector isn't deprecated.
|
|
|
|
|
|
#7 | |
|
Professional Programmer
|
Quote:
|
|
|
|
|
|
|
#8 | |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,031
Rep Power: 5
![]() |
Quote:
![]()
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
|
#9 | |
|
Programmer
|
Quote:
TecBrain: What version of Java are you running? JD |
|
|
|
|
|
|
#10 | |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
Quote:
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|