为什么要生成classNotFoundException?

时间:2014-03-17 01:27:15

标签: java classnotfoundexception

为什么我的程序会产生此异常:

  

线程“main”中的异常java.lang.ClassNotFoundException:   writecoursefile.Course

何时在我的代码中定义了课程?

我不确定“writcoursefile”是什么,因为这不是我程序中的任何地方。

此程序用于反序列化.ser文件,排序,然后打印到csv文件。我只是去反序列化部分。课程由我的老师提供。

    /*
 fallListSort Application
Created for CSci 112 by Steve Pesce
last Edited 3/16

 */

package falllistsort;
import java.io.*;


public class FallListSort {

    public static void main(String[] args) throws Exception
    {
        //declare new course array
       Course[] fall2014 = new Course[24];

       //use fall2014.ser to define fall2014[]
       fall2014 = readFromFile();

       //Test: print array
       for (Course course: fall2014)
       {
           System.out.println(course.toString());
       }


    }

    public static Course[] readFromFile() throws Exception
    {
        Course[] course = null; //course object to holde file data

        //declare file and object stream variables and initialize to null
        FileInputStream fallFile = null;
        ObjectInputStream infile = null;

        try
        {   //File and stream objects
            fallFile = new FileInputStream("fall2014.ser");
            infile = new ObjectInputStream(fallFile);

            //read objects from file
            course = (Course[]) infile.readObject();


        } catch (IOException exc) 
        {
            exc.printStackTrace();
        }finally
        {
            infile.close();
        }

        return course;
    }// end readfromFile()

    public static void writeCSV(Course[] courseArray, int count) throws Exception
    {
        java.io.File courseCSV = new java.io.File("courses.csv");

        java.io.PrintWriter outfile = new java.io.PrintWriter(courseCSV);


    }
}
class Course implements Serializable {


    private String campus;  // the campus on which the course is offered
    private String course;  // the course number, such as CSCI 111
    private String section; // the section number
    private String crn;     // the CRN for this section
    private int credits;    // the number od credits for the course
    private String time;    // the time the course is offered, such as 8:00 to 10:00 A.M.
    private String days;    // the Days the course is offered, suhc as MW


    // constructors
    Course() {
    }

    Course(String course, String section, String crn, int credits) {
        this.course = course;
        this.section = section;
        this.crn = crn;
        this.credits = credits;
    }   // end Course() initalizing

    // muatator methods

    public void setCampus(String cmp) {
        this.campus = cmp;
    }// end setCampus()

    public void setCourse(String crse) {
        this.course = crse;
    }// end setCourse()

    public void setSection(String sect) {
        this.section = sect;
    }   // end setSection()

    public void setCRN(String crn) {
        this.crn  = crn;
    }   // end setCRN()

    public void setCredits(int cr) {
        this.credits = cr;
    }   // end setCredits()

    public void setTime(String tm) {
        this.time = tm;
    }// end setTime()

    public void setDays(String days) {
        this.days = days;
    }// end setDays()


    // accessor methods

    public String getCampus() {
        return campus;
    }   // end getCampus()

    public String getCourse() {
        return course;
    }   // end Course()

    public String getSection() {
        return section;
    }   // end getSection()

    public String getCRN() {
        return crn;
    }   // end getCRN()

    public int getCredits() {
        return credits;
    }   // end getCredits()

    public String getTime() {
        return time;
    }   // end getTime()

    public String getDays() {
        return days;
    }   // end getDays()


    // method to compare by CRN using the String class compareTo()
    public int compareTo(Course other) {
        return this.crn.compareTo(other.getCRN());
    }   // end compareTO()

    // method to return properties as a string
    public String toString() {

        return    campus + " "
                + course + " "
                + section + " "
                + crn + " "
                + credits + " "
                + time + " "
                + days;

    }    // end toString()

    // You will need to add a method to return properties as a CSV string on one line
/*    public String toCSVString() {


    }  // end toCSVString()
  */

}// end class Course

0 个答案:

没有答案