Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: "Cannot find symbol" compilation error

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default "Cannot find symbol" compilation error

    Hi! I have two errors in my code when I try to compile, in the lines " Course newCourse = new Course(cName, cStart, cEnd);" and "lastEnd = course.getETime;" and I'm not sure why the code is having trouble accessing the course class. Any help would be appreciated.


    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Scanner;
     
    public class Fitter {
     
    	private ArrayList<Course> courses;
    	private ArrayList<Course> fittedCourses;
    	private double cEndTime;
    	private double cStartTime;
    	private double lastEnd = 8;
     
    		public Fitter(File courseList) throws FileNotFoundException, NumberFormatException{
    		//initialize variables
    		courses = new ArrayList<Course>();
    		fittedCourses = new ArrayList<Course>();
    		Scanner courseScanner = new Scanner(courseList);
    		//scan lines in File
    		while(courseScanner.hasNextLine()) {
    			//get name and start/ end times
    			String cName = courseScanner.nextLine();
    			String cStart = courseScanner.nextLine();
    			String cEnd = courseScanner.nextLine();
     
    			//convert times into decimals, first checking number formatting
    			String[] cStartSplit = cStart.split(":");
     
    			double cStartH = Double.parseDouble(cStartSplit[0]);
    			double cStartM = Double.parseDouble(cStartSplit[1]);
     
    			if ((cStartH < 8) || (cStartH > 17))
    				throw new NumberFormatException();
    			if (cStartM > 60)
    				throw new NumberFormatException();
     
     
    			String[] cEndSplit = cEnd.split(":");
     
     
    			double cEndH = Double.parseDouble(cEndSplit[0]);
    			double cEndM = Double.parseDouble(cEndSplit[1]);
     
    			if ((cEndH < 8) || (cEndH > 17))
    				throw new NumberFormatException();
    			if (cStartM > 60)
    				throw new NumberFormatException();
     
     
    			Course newCourse = new Course(cName, cStart, cEnd);
    			courses.add(newCourse);
    			//skip blank line
    			if(courseScanner.hasNextLine())
    				courseScanner.nextLine();
    		}
    	}
     
    	public void fit() throws NumberFormatException{
    		//sort by size
    		Collections.sort(courses);
    		//for each course (starting with earliest end time) add
    		//if no conflict exists
    		for(Course course : courses) {
    			if(lastEnd < course.getSTime())
    				lastEnd = course.getETime;
    		}
    	}
     
     
    	public String toString() {
    		String info = "We made the following schedule: \n\n";
    		for(Course course : fittedCourses) {
    			info += course.toString() + "\n";
    		}
    		return info;
    	}
     
    }

    Thanks! The Course class can be posted if necessary


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: "Cannot find symbol" compilation error

    Please post the full text of the error messages. Your edited version leaves off important information.

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: "Cannot find symbol" compilation error

    Quote Originally Posted by Norm View Post
    Please post the full text of the error messages. Your edited version leaves off important information.
    ./Fitter.java:56: cannot find symbol
    symbol: constructor Course(java.lang.String,java.lang.String,java.lang .String)
    location: class Course

    Course newCourse = new Course(cName, cStart, cEnd);


    ./Fitter.java:71: cannot find symbol
    symbol: variable getETime
    location: class Course

    lastEnd = course.getETime;

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: "Cannot find symbol" compilation error

    Course(java.lang.String,java.lang.String,java.lang .String)
    Does the Course class have a constructor that takes 3 Strings?
    cannot find symbol
    symbol: variable getETime
    The compiler can not find that variable in the Course class.

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: "Cannot find symbol" compilation error

    Quote Originally Posted by Norm View Post
    Does the Course class have a constructor that takes 3 Strings?
    Yes - it's written as
    public Course(String cName, double cStart, double cEnd){
    ...
    }


    The compiler can not find that variable in the Course class.[/QUOTE]
    Just realized, I forgot the parentheses. Sorry about that; that was a silly mistake...

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: "Cannot find symbol" compilation error

    You must count differently than I do. I see one String followed by two doubles in the constructor code that you just posted in #5.

  7. #7
    Member
    Join Date
    Dec 2011
    Posts
    48
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: "Cannot find symbol" compilation error

    Quote Originally Posted by collegejavastudent View Post
    Yes - it's written as
    public Course(String cName, double cStart, double cEnd){
    ...
    }
    How are you sure this is 3 Strings?

  8. #8
    Junior Member
    Join Date
    Dec 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: "Cannot find symbol" compilation error

    Aaah, just realized that I left out the code in which I was going to make that a double...

    Thanks! Don't I feel silly...

Similar Threads

  1. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  2. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  3. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM
  4. Replies: 1
    Last Post: March 15th, 2010, 10:03 PM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM