I have an employee class see atthachement whic compiles fine and i have written some code called EmployeeAdd which uses the Employee Class which was deifining an Employee.

However my problem is when i am trying to import the Employee in to EmployeeAdd the error message i am getting is the following

error expected . at end of the line after import EmployeeAdd.java it just does not compile for some reason

This code was working fine before i am using jdk version 2.0

If anyone can help me plz

Thanks

Richard

Attachments
import java.io.*;
import java.util.*;


class Employee implements Serializable
{
		private int EmpNum; 
		private String surname;
		private String firstNames;
		private String sex;
		private String birthdate;
		private String post;
		private long salary;
		private String notes;

		public Employee( int empno, String surnameData, String firstNamesData, String SexData, String dobData,  String postData, long salaryData, String NotesData)

		{
			EmpNum= empno;
			surname = surnameData;
			firstNames = firstNamesData;
			sex = SexData;
			birthdate = dobData;
			post = postData;
			salary = salaryData;
			notes = NotesData;
		}
		
		public int getEmpNo()
      		{
			return EmpNum;
		
		}

		
		public String getSurname()
		{
			return surname;
		}


		public void changeSurname(String newSurname)
		{
		surname = newSurname;
		}

		public String getFirstNames()
		{
			return firstNames;
		}

		public String getSex()
		{
			return sex;
		}
	
		public String getDob()
		{
			return birthdate;
		}

		public String getPost()
		{
			return post;
		}

		public void changePost(String newPost)
		{
			post = newPost;
		}

		

		public long getSalary()
		{
			return salary;
		}

		public void changeSalary(long newSalary)
		{
			salary = newSalary;
		}
		
		public String getNotes()
		{
			return notes;
		}

		public void changeNotes(String newNotes)
		{
			notes = newNotes;
		}		

}
import java.io.*;
import java.util.*;
import Employee;



public class EmployeeAdd
{
	public static void main(String[] args) throws IOException, FileNotFoundException,
								 ClassNotFoundException
	{
		ObjectOutputStream outStream = 
		  new ObjectOutputStream(
			new FileOutputStream("personnel.dat"));


		Vector empVec = new Vector();

		Employee[] empl = 
		  { new Employee(1 , "Black", "Frank David", "male", "13/05/85", "manager", 25000, "Very Efficient"),
		    new Employee(2 , "Johnson", "Rebecca", "female", "16/11/74", "secetary", 14000, "Quite Lazy"),
		    new Employee(3 , "Boulder", "Ben Jack", "male", "12/02/80", "accounts", 22000, ""),
		    new Employee(4 , "Jones", "Claire Emma", "female", "23/06/75", "checkouts", 8000, "Slow"),
		    new Employee(5 , "Weaver", "Derek Robert", "male", "15/12/80", "developement", 25000, "Astute"),
		    new Employee(6 , "Gerrad", "Steven David", "male", "01/02/78", "anaylst", 20000, "Intelligent")};

		for (int i = 0; i<empl.length; i++)		
			empVec.add(empl[i]);

		outStream.writeObject(empVec);
		outStream.close();		
	
	}	

}
import java.io.*;
import java.util.*;
import Employee;

The problem is with import Employee; --- you can't import classes from the same package without at least giving the package name/whatever.

Just remove import Employee; and you should be fine. As long as the classes are in the same directory/package, they're automatically available to one another. ;)

It is frowned upon to place classes in the "main" or "default" or "unnamed" package. And this is one of the problems that arise from that. Place each of these classes into a package, then import package.Employee and everything will be okay. Also, if they are in the same package, you don't need the import statement, at all.

import java.io.*;
import java.util.*;
import Employee;

The problem is with import Employee; --- you can't import classes from the same package without at least giving the package name/whatever.

Just remove import Employee; and you should be fine. As long as the classes are in the same directory/package, they're automatically available to one another. ;)

Part of the problem, is tht they are not in a package at all.

This article has been dead for over six months. Start a new discussion instead.