Results 1 to 2 of 2
  1. #1
    rmartyce is offline Member
    Join Date
    May 2008
    Posts
    1
    Rep Power
    0

    Default symbol not found error

    I have a program (see below). Can someone tell me why I'm getting the error...

    C:\CourseUnits.java:95: cannot find symbol
    symbol : variable CourseUnitArray
    location: class CourseUnits
    CourseUnitArray[0] = new CourseUnits("name","num");
    ^
    C:\CourseUnits.java:95: cannot find symbol
    symbol : constructor CourseUnits(java.lang.String,java.lang.String)
    location: class CourseUnits
    CourseUnitArray[0] = new CourseUnits("name","num");
    ^
    2 errors

    Tool completed with exit code 1

    The CourseUnits constructor is there. The classpath is .;PATH;C:\;
    I've been stumped for 2 days, so any assistance is greatly appreciated.



    import java.lang.*;
    import java.util.*;
    import java.io.*;
    import java.util.Scanner;

    public class CourseUnits {
    private Integer courseUnitID;
    private String courseUnitName;
    private String courseUnitNum;
    private static int lastAssignedID = 10000;
    //in the real world the ArrayList would not be used. Instead a datbase table would
    //be used.
    private static ArrayList<CourseUnits> courseUnitArray = new ArrayList<CourseUnits>();


    //default constructor - no parameters
    public void CourseUnits(){
    }

    public void CourseUnits(String cName, String cNum){
    courseUnitName = cName;
    courseUnitNum = cNum;
    courseUnitID = createCourseUnitID();
    courseUnitArray.add(this);
    }

    private static int createCourseUnitID() {
    ++lastAssignedID;
    return lastAssignedID;
    }

    public String courseUnitName () {
    return this.courseUnitName;
    }


    public String courseUnitNum () {
    return this.courseUnitNum;
    }


    public int courseUnitID () {
    return this.courseUnitID;
    }

    public static void listCourseUnit(int idx){
    CourseUnits holdCourseUnit = new CourseUnits();
    holdCourseUnit = courseUnitArray.get(idx);
    System.out.println(holdCourseUnit.courseUnitID + " " + holdCourseUnit.courseUnitName + " " + holdCourseUnit.courseUnitNum);
    }

    public static void listCourseUnitArray(){
    CourseUnits holdCourseUnit = new CourseUnits();
    for (int i=0; i < courseUnitArray.size(); i++){
    holdCourseUnit = courseUnitArray.get(i);
    System.out.println(holdCourseUnit.courseUnitID + " " + holdCourseUnit.courseUnitName + " " + holdCourseUnit.courseUnitNum);
    }
    }

    public static int findCourseUnit(int inCourseUnitID){
    CourseUnits holdCourseUnit = new CourseUnits();
    for (int i=0; i < courseUnitArray.size(); i++){
    holdCourseUnit = courseUnitArray.get(i);
    if (inCourseUnitID == holdCourseUnit.courseUnitID())
    return i;
    }
    return -1;
    }

    public static void deleteCourseUnit(int idx){
    courseUnitArray.remove(idx);
    }



    private static BufferedReader stdin =
    new BufferedReader( new InputStreamReader( System.in ) );

    Scanner input = new Scanner( System.in );

    public static void main(String[] args) throws IOException {

    if (courseUnitArray.size() == 0)
    System.out.println("There are no courses");
    else
    listCourseUnitArray();


    String [] courseUnitNames = {"English 101", "Algebra 101","Biology 101","Geometry 101","Englis Literature"};
    String [] courseUnitNums = {"E101","M101","Sci101","M102","E103"};

    CourseUnits courseUnitArray[] = new CourseUnits[5];
    CourseUnitArray[0] = new CourseUnits("name","num");

    }
    }


    thanks.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Defining the constructor is wrong. There is no return type in constructor. Even no void there.

    You have use the same name for ArrayList as well as object array. You should rename one of them.

    Java Code:
    import java.util.*;
    import java.io.*;
    import java.util.Scanner;
    
    public class CourseUnits {
        private Integer courseUnitID;
        private String courseUnitName;
        private String courseUnitNum;
        private static int lastAssignedID = 10000;
            //in the real world the ArrayList would not be used. Instead a datbase table would
            //be used.
        private static ArrayList<CourseUnits> courseUnitArray = new ArrayList<CourseUnits>();
    
        //default constructor - no parameters
        public CourseUnits() {
        }
    
        public CourseUnits(String cName, String cNum){
            courseUnitName = cName;
            courseUnitNum = cNum;
            courseUnitID = createCourseUnitID();
            courseUnitArray.add(this);
        }
    
        private static int createCourseUnitID() {
            ++lastAssignedID;
            return lastAssignedID;
        }
    
        public String courseUnitName () {
            return this.courseUnitName;
        }
    
        public String courseUnitNum () {
            return this.courseUnitNum;
        }
    
        public int courseUnitID () {
            return this.courseUnitID;
        }
    
        public static void listCourseUnit(int idx){
            CourseUnits holdCourseUnit = new CourseUnits();
            holdCourseUnit = courseUnitArray.get(idx);
            System.out.println(holdCourseUnit.courseUnitID + " " + holdCourseUnit.courseUnitName + " " + holdCourseUnit.courseUnitNum);
        }
    
        public static void listCourseUnitArray(){
            CourseUnits holdCourseUnit = new CourseUnits();
            for (int i=0; i < courseUnitArray.size(); i++){
                holdCourseUnit = courseUnitArray.get(i);
                System.out.println(holdCourseUnit.courseUnitID + " " + holdCourseUnit.courseUnitName + " " + holdCourseUnit.courseUnitNum);
            }
        }
    
        public static int findCourseUnit(int inCourseUnitID){
            CourseUnits holdCourseUnit = new CourseUnits();
            for (int i=0; i < courseUnitArray.size(); i++){
                holdCourseUnit = courseUnitArray.get(i);
                if (inCourseUnitID == holdCourseUnit.courseUnitID())
                    return i;
            }
            return -1;
        }
    
        public static void deleteCourseUnit(int idx){
            courseUnitArray.remove(idx);
        }
    
        private static BufferedReader stdin =
            new BufferedReader( new InputStreamReader( System.in ) );
    
        Scanner input = new Scanner( System.in );
        @SuppressWarnings("empty-statement")
        public static void main(String[] args) throws IOException {
            if (courseUnitArray.size() == 0)
                System.out.println("There are no courses");
            else
                listCourseUnitArray();
            
            String [] courseUnitNames = {"English 101", "Algebra 101","Biology 101","Geometry 101","Englis Literature"};
            String [] courseUnitNums = {"E101","M101","Sci101","M102","E103"};
    
            CourseUnits courseUnitArray2[] = new CourseUnits[5];
            courseUnitArray2[0] = new CourseUnits("name", "num");;
    
        }
    }

Similar Threads

  1. Error: no class definition found
    By toby in forum New To Java
    Replies: 6
    Last Post: 08-28-2011, 10:32 PM
  2. JRE rtapplet class not found error
    By avinash.natekar in forum Java Applets
    Replies: 11
    Last Post: 04-02-2009, 08:02 AM
  3. Error: cannot find symbol
    By silvia in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:39 AM
  4. Error: cannot find symbol
    By cachi in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 08:12 PM
  5. Error: cannot resolve symbol, help me
    By mathias in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 08-06-2007, 02:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •