Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 21st, 2005, 1:42 PM   #1
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
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 errors

import 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.
TecBrain is offline   Reply With Quote
Old Dec 21st, 2005, 2:14 PM   #2
JDStud6
Programmer
 
Join Date: Jan 2005
Location: Charleston, SC www.wareonearth.com
Posts: 57
Rep Power: 4 JDStud6 is on a distinguished road
Send a message via AIM to JDStud6
import java.util.Vector;

JD
JDStud6 is offline   Reply With Quote
Old Dec 21st, 2005, 5:54 PM   #3
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
Quote:
Originally Posted by JDStud6
import java.util.Vector;

JD
Didnt Help.

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.
TecBrain is offline   Reply With Quote
Old Dec 21st, 2005, 6:18 PM   #4
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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.
titaniumdecoy is offline   Reply With Quote
Old Dec 21st, 2005, 6:28 PM   #5
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 310
Rep Power: 3 andro is on a distinguished road
Send a message via AIM to andro
1. Vector<String> myVector = new Vector<String>();

and

2. You should use ArrayList, Vector is deprecated.
andro is offline   Reply With Quote
Old Dec 21st, 2005, 6:30 PM   #6
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Vector isn't deprecated.
titaniumdecoy is offline   Reply With Quote
Old Dec 21st, 2005, 6:50 PM   #7
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 310
Rep Power: 3 andro is on a distinguished road
Send a message via AIM to andro
Quote:
Originally Posted by titaniumdecoy
Vector isn't deprecated.
Whoops, my mistake. Thought I read that it was :O
andro is offline   Reply With Quote
Old Dec 21st, 2005, 11:26 PM   #8
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,031
Rep Power: 5 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by andro
2. You should use ArrayList, Vector is deprecated.
He should use C++; Java is deprecated.
__________________
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
lectricpharaoh is offline   Reply With Quote
Old Dec 22nd, 2005, 7:51 AM   #9
JDStud6
Programmer
 
Join Date: Jan 2005
Location: Charleston, SC www.wareonearth.com
Posts: 57
Rep Power: 4 JDStud6 is on a distinguished road
Send a message via AIM to JDStud6
Quote:
Originally Posted by lectricpharaoh
He should use C++; Java is deprecated.
funny guy

TecBrain: What version of Java are you running?

JD
JDStud6 is offline   Reply With Quote
Old Dec 22nd, 2005, 10:16 AM   #10
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
Quote:
Originally Posted by JDStud6
funny guy

TecBrain: What version of Java are you running?

JD
I use Linux(Slackware) as an OS, I did only install jdk1.5.0_05 and Netbeans 4.1, i use a text file to create my projectc and compiling it using javac.
__________________
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.
TecBrain is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:26 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC