hello friends..got a problem again..

I'm developing a software for one of our assignments.I have coded that program using Netbeans but we have to upload the assignment as one java file.So I created one java file and again checked in netbeans as a single file.It works perfectly.And then I tried to compile and run that file using command prompt.But then It generate some errors. I'm attaching a image of errors generated and the source file.Please can you people help me out ?

import java.io.*;
import java.util.*;
 class newMain {


    public static void main(String[] args) {

     ArrayList<house> House = new ArrayList<house>();
        house tempHouse=new house();
        factoryORstate fac =new factoryORstate();



int input=0,nic;
String temp;
try{
        BufferedReader buff2 = new BufferedReader(new InputStreamReader(System.in));
while(true){


        System.out.print("\n\nWhat do you wanto do ?");
         System.out.print("\n Add new person ------------------ 1  ");
         System.out.print("\n view person details ------------- 2  ");
         System.out.print("\n Add new House ------------------- 3  ");
         System.out.print("\n Add new Factory/State ----------- 4  ");
         System.out.print("\n exit ---------------------------- 6  ");

       //  buff2.reset();
          temp = buff2.readLine();
          input=Integer.parseInt(temp);
         // System.out.print(input);

          switch(input){

    case 1:
       // home[0].setData();
       nic= tempHouse.setData();
        tempHouse.save(nic);
        break;

    case 2:

        System.out.print("\n Enter the NIC no of the person   : ");
        temp = buff2.readLine();
        nic=Integer.parseInt(temp);
        System.out.print(tempHouse.getDetails(nic));
      break;

    case 3:
        House.add(tempHouse);
        tempHouse.member.clear();
        break;
    case 4:
        fac.setData();
        break;


    case 6:
        System.exit(0);

    default:
        continue;

}


    }

    }catch(Exception e){
           System.out.print("\n Error--"+e.toString());
        }





    }

}


 abstract class building {

    private int buildingNo;
    private ArrayList<String> houses = new ArrayList<String>();
    private ArrayList<String> lands = new ArrayList<String>();
    private ArrayList<String> vehicles = new ArrayList<String>();

    public void setNo(int inNo){
    buildingNo=inNo;
    }
    public void setHouse(String house){
     houses.add(house);
    }

    public void setLand(String land){

        lands.add(land);
    }
    public void setVehicle(String vehi){

        vehicles.add(vehi);

    }

public int getNo(){
    return buildingNo;
}
public ArrayList getHouse(){
    return houses;
}
public ArrayList getland(){
    return lands;
}
public ArrayList getvehicle(){
    return vehicles;
}


}


class house extends building{

   // private ArrayList<person> member =new ArrayList<person>();
    private int numberOdChildren;


     Hashtable member =new Hashtable();



    public int setData(){
        int inNIC=-1;
         person tempPerson =new person();

         try{
        BufferedReader buff1 = new BufferedReader(new InputStreamReader(System.in));
        person tempPerson2 =new person();

        // System.out.print("\n\n\n\n "+tempPerson.pData.getName());
/*get personal data*/
        System.out.print("\nEnter personal data\n");
        System.out.print("Full Name  :");
        tempPerson2.pData.setName(buff1.readLine());

//        System.out.print("Date Of Birth yyyy/mm/dd :");
//        tempPerson.pData.setDateOfBirth(buff1.readLine());

        System.out.print("ID number  :");
        inNIC=Integer.parseInt(buff1.readLine());
        tempPerson2.pData.setNICno(inNIC);

        System.out.print("Contact number xxxxxxxxxx :");
        tempPerson.pData.setcontactNo(Integer.parseInt(buff1.readLine()));

        System.out.print("nGender (male/female) :");
        tempPerson.setSex(buff1.readLine());

        System.out.print("Relationship to cheif occupant :");
        tempPerson.setRelationship(buff1.readLine());

        System.out.print("DS division  :");
        tempPerson.setDivision(buff1.readLine());

        System.out.print("District  :");
        tempPerson.setDistrict(buff1.readLine());
/*get professional data*/
        System.out.print("\nEnter professional data\n");
        System.out.print("Profession  :");
        tempPerson.proData.setProfession(buff1.readLine());

         System.out.print("Salary  :");
        tempPerson.proData.setSalary(Integer.parseInt(buff1.readLine()));
/*get Educational data*/
        System.out.print("\nEnter Educational data\n");
        System.out.print("School  :");
        tempPerson.eData.setSchool(buff1.readLine());

        System.out.print("Advanced Level Results  :");
        tempPerson.eData.setResult(buff1.readLine());

        System.out.print("Details of Higher Studies  :");
        tempPerson.eData.setHigherStudy(buff1.readLine());

member.put(tempPerson2.pData.getNICno(), tempPerson2);

//buff1.close();

   }catch(IOException e){
        System.out.println("\nError--"+e.toString());
    }
         return inNIC;
    }

    void setChild(int num){
        numberOdChildren=num;
    }



    public String getDetails(int NIC){

       person tempPerson =new person();
       tempPerson=(person)member.get(NIC);

    return "name  :"+tempPerson.pData.getName()+"\n "
            + "Date Of Birth    :"+tempPerson.pData.getDateOfBirth()+"\n "
            + "ID number    :"+tempPerson.pData.getNICno()+"\n "
            + "Contact number   :"+tempPerson.pData.getcontactNo()+"\n "
            + "Gender   :"+tempPerson.getSex()+"\n "
            + "Relationship to cheif occupant   :"+tempPerson.getRelationship()+"\n "
            + "DS division  :"+tempPerson.getDivision()+"\n "
            + "District :"+tempPerson.getDistrict()+"\n "
            + "Profession   :"+tempPerson.proData.getProfession()+"\n"
            + "Salary   :"+tempPerson.proData.getSalary()+"\n "
            + "School   :"+tempPerson.eData.getSchool()+"\n "
            + "Advanced Level Results   :"+tempPerson.eData.getresult()+"\n "
            + "Details of Higher Studies    :"+tempPerson.eData.getHigherStudy()+"\n ";




}

    public void save(int NIC){

        person tempPerson =new person();
        tempPerson=(person)member.get(NIC);

        try{

          BufferedWriter buffw = new BufferedWriter(new FileWriter("d:\\data.txt",true));
          buffw.write(getDetails(NIC));
          buffw.newLine();
          buffw.close();

        }catch(Exception e){
        System.out.print("Error-- "+e.toString());
        }


    }

}

 class person {

    private String relationshipToChiefOccupant;
    private String sex,DSdivision,district;
    personalData pData = new personalData();
    professionalData proData = new professionalData();
    educationalData eData =new educationalData();

public void setData(String relationship,String inSex,String inDivision,String inDistrict){
    relationshipToChiefOccupant=relationship;
    sex = inSex;
    DSdivision=inDivision;
    district=inDistrict;

}
public void setRelationship(String relationship){

     relationshipToChiefOccupant=relationship;
}

public void setSex(String inSex){
    sex = inSex;
}

public void setDivision(String inDivision){
    DSdivision=inDivision;
}

public void setDistrict(String inDistrict){
     district=inDistrict;
}

public String getRelationship(){
    return relationshipToChiefOccupant;
}

public String getSex(){
    return sex;
}

public String getDivision(){
    return DSdivision;
}

public String getDistrict(){
    return district;
}




}


 class personalData {
    private String name,dateOfBirth;
    private int NICno,contactNo;

    public void setName(String inName){
        name=inName;
    }
    public void setDateOfBirth(String dob){
        dateOfBirth=dob;
    }
    public void setNICno(int NIC){
        NICno=NIC;
    }
    public void setcontactNo(int contact){
        contactNo=contact;
    }

    public String getName(){
        return name;
    }
    public String getDateOfBirth(){
        return dateOfBirth;
    }
    public int getNICno(){
        return NICno;
    }
    public int getcontactNo(){
        return contactNo;
    }

}


 class professionalData {
    private String profession;
    private int salary;

    public void setProfession(String inprofession){
        profession=inprofession;
    }

    public void setSalary(int inSalary){
        salary=inSalary;
    }

    public String getProfession(){
        return profession;
    }
    public int getSalary(){
        return salary;
    }

}

 class educationalData {

    private String school,resultAL,higherStudies;

    public void setSchool(String inSchool){
        school=inSchool;
    }
    public void setResult(String result){
        resultAL=result;
    }

    public void setHigherStudy(String inHigherStdy){
        higherStudies=inHigherStdy;
    }

    public String getSchool(){
        return school;
    }
    public String getresult(){
        return resultAL;
    }
    public String getHigherStudy(){
        return higherStudies;
    }


}

 class factoryORstate extends building {
    private String type,size,owner;
    private int workforce;

    public void setData(){
        try{
        BufferedReader buff1 = new BufferedReader(new InputStreamReader(System.in));

        System.out.print("\nEnter data for factory/state\n");
        System.out.print("Type (facotory or state) :");
       setType(buff1.readLine());

       System.out.print("size (large, medium or small) :");
       setSize(buff1.readLine());

       System.out.print("Owners name :");
       setOwner(buff1.readLine());

       System.out.print("size of work force :");
       setWorkForce(Integer.parseInt(buff1.readLine()));




        }catch(Exception e){

        }
    }

    public void setType(String inType){
        type=inType;
    }
    public void setSize(String inSize){
        size=inSize;
    }
    public void setOwner(String inOwner){
        owner=inOwner;
    }
    public void setWorkForce(int inWorkForce){
        workforce=inWorkForce;
    }

    public String getType(){
        return type;
    }
    public String getSize(){
        return size;
    }
    public String getOwner(){
        return owner;
    }
    public int getWorkForce(){
        return workforce;
    }

}

errors : http://dl.dropbox.com/u/25500756/er.PNG

Edited 5 Years Ago by baby_c: n/a

Attachments Capture.PNG 13.13 KB
import java.io.*;
import java.util.*;
 class newMain {


    public static void main(String[] args) {

     ArrayList<house> House = new ArrayList<house>();
        house tempHouse=new house();
        factoryORstate fac =new factoryORstate();



int input=0,nic;
String temp;
try{
        BufferedReader buff2 = new BufferedReader(new InputStreamReader(System.in));
while(true){


        System.out.print("\n\nWhat do you wanto do ?");
         System.out.print("\n Add new person ------------------ 1  ");
         System.out.print("\n view person details ------------- 2  ");
         System.out.print("\n Add new House ------------------- 3  ");
         System.out.print("\n Add new Factory/State ----------- 4  ");
         System.out.print("\n exit ---------------------------- 6  ");

       //  buff2.reset();
          temp = buff2.readLine();
          input=Integer.parseInt(temp);
         // System.out.print(input);

          switch(input){

    case 1:
       // home[0].setData();
       nic= tempHouse.setData();
        tempHouse.save(nic);
        break;

    case 2:

        System.out.print("\n Enter the NIC no of the person   : ");
        temp = buff2.readLine();
        nic=Integer.parseInt(temp);
        System.out.print(tempHouse.getDetails(nic));
      break;

    case 3:
        House.add(tempHouse);
        tempHouse.member.clear();
        break;
    case 4:
        fac.setData();
        break;


    case 6:
        System.exit(0);

    default:
        continue;

}


    }

    }catch(Exception e){
           System.out.print("\n Error--"+e.toString());
        }





    }

}


 abstract class building {

    private int buildingNo;
    private ArrayList<String> houses = new ArrayList<String>();
    private ArrayList<String> lands = new ArrayList<String>();
    private ArrayList<String> vehicles = new ArrayList<String>();

    public void setNo(int inNo){
    buildingNo=inNo;
    }
    public void setHouse(String house){
     houses.add(house);
    }

    public void setLand(String land){

        lands.add(land);
    }
    public void setVehicle(String vehi){

        vehicles.add(vehi);

    }

public int getNo(){
    return buildingNo;
}
public ArrayList getHouse(){
    return houses;
}
public ArrayList getland(){
    return lands;
}
public ArrayList getvehicle(){
    return vehicles;
}


}


class house extends building{

   // private ArrayList<person> member =new ArrayList<person>();
    private int numberOdChildren;


     Hashtable member =new Hashtable();



    public int setData(){
        int inNIC=-1;
         person tempPerson =new person();

         try{
        BufferedReader buff1 = new BufferedReader(new InputStreamReader(System.in));
        person tempPerson2 =new person();

        // System.out.print("\n\n\n\n "+tempPerson.pData.getName());
/*get personal data*/
        System.out.print("\nEnter personal data\n");
        System.out.print("Full Name  :");
        tempPerson2.pData.setName(buff1.readLine());

//        System.out.print("Date Of Birth yyyy/mm/dd :");
//        tempPerson.pData.setDateOfBirth(buff1.readLine());

        System.out.print("ID number  :");
        inNIC=Integer.parseInt(buff1.readLine());
        tempPerson2.pData.setNICno(inNIC);

//        System.out.print("Contact number xxxxxxxxxx :");
//        tempPerson.pData.setcontactNo(Integer.parseInt(buff1.readLine()));
//
//        System.out.print("nGender (male/female) :");
//        tempPerson.setSex(buff1.readLine());
//
//        System.out.print("Relationship to cheif occupant :");
//        tempPerson.setRelationship(buff1.readLine());
//
//        System.out.print("DS division  :");
//        tempPerson.setDivision(buff1.readLine());
//
//        System.out.print("District  :");
//        tempPerson.setDistrict(buff1.readLine());
///*get professional data*/
//        System.out.print("\nEnter professional data\n");
//        System.out.print("Profession  :");
//        tempPerson.proData.setProfession(buff1.readLine());
//
//         System.out.print("Salary  :");
//        tempPerson.proData.setSalary(Integer.parseInt(buff1.readLine()));
///*get Educational data*/
//        System.out.print("\nEnter Educational data\n");
//        System.out.print("School  :");
//        tempPerson.eData.setSchool(buff1.readLine());
//
//        System.out.print("Advanced Level Results  :");
//        tempPerson.eData.setResult(buff1.readLine());
//
//        System.out.print("Details of Higher Studies  :");
//        tempPerson.eData.setHigherStudy(buff1.readLine());

member.put(tempPerson2.pData.getNICno(), tempPerson2);

//buff1.close();

   }catch(IOException e){
        System.out.println("\nError--"+e.toString());
    }
         return inNIC;
    }

    void setChild(int num){
        numberOdChildren=num;
    }



    public String getDetails(int NIC){

       person tempPerson =new person();
       tempPerson=(person)member.get(NIC);

    return "name  :"+tempPerson.pData.getName()+"\n "
            + "Date Of Birth    :"+tempPerson.pData.getDateOfBirth()+"\n "
            + "ID number    :"+tempPerson.pData.getNICno()+"\n "
            + "Contact number   :"+tempPerson.pData.getcontactNo()+"\n "
            + "Gender   :"+tempPerson.getSex()+"\n "
            + "Relationship to cheif occupant   :"+tempPerson.getRelationship()+"\n "
            + "DS division  :"+tempPerson.getDivision()+"\n "
            + "District :"+tempPerson.getDistrict()+"\n "
            + "Profession   :"+tempPerson.proData.getProfession()+"\n"
            + "Salary   :"+tempPerson.proData.getSalary()+"\n "
            + "School   :"+tempPerson.eData.getSchool()+"\n "
            + "Advanced Level Results   :"+tempPerson.eData.getresult()+"\n "
            + "Details of Higher Studies    :"+tempPerson.eData.getHigherStudy()+"\n ";




}

    public void save(int NIC){

        person tempPerson =new person();
        tempPerson=(person)member.get(NIC);

        try{

          BufferedWriter buffw = new BufferedWriter(new FileWriter("d:\\data.txt",true));
          buffw.write(getDetails(NIC));
          buffw.newLine();
          buffw.close();

        }catch(Exception e){
        System.out.print("Error-- "+e.toString());
        }


    }

}

 class person {

    private String relationshipToChiefOccupant;
    private String sex,DSdivision,district;
    personalData pData = new personalData();
    professionalData proData = new professionalData();
    educationalData eData =new educationalData();

public void setData(String relationship,String inSex,String inDivision,String inDistrict){
    relationshipToChiefOccupant=relationship;
    sex = inSex;
    DSdivision=inDivision;
    district=inDistrict;

}
public void setRelationship(String relationship){

     relationshipToChiefOccupant=relationship;
}

public void setSex(String inSex){
    sex = inSex;
}

public void setDivision(String inDivision){
    DSdivision=inDivision;
}

public void setDistrict(String inDistrict){
     district=inDistrict;
}

public String getRelationship(){
    return relationshipToChiefOccupant;
}

public String getSex(){
    return sex;
}

public String getDivision(){
    return DSdivision;
}

public String getDistrict(){
    return district;
}




}


 class personalData {
    private String name,dateOfBirth;
    private int NICno,contactNo;

    public void setName(String inName){
        name=inName;
    }
    public void setDateOfBirth(String dob){
        dateOfBirth=dob;
    }
    public void setNICno(int NIC){
        NICno=NIC;
    }
    public void setcontactNo(int contact){
        contactNo=contact;
    }

    public String getName(){
        return name;
    }
    public String getDateOfBirth(){
        return dateOfBirth;
    }
    public int getNICno(){
        return NICno;
    }
    public int getcontactNo(){
        return contactNo;
    }

}


 class professionalData {
    private String profession;
    private int salary;

    public void setProfession(String inprofession){
        profession=inprofession;
    }

    public void setSalary(int inSalary){
        salary=inSalary;
    }

    public String getProfession(){
        return profession;
    }
    public int getSalary(){
        return salary;
    }

}

 class educationalData {

    private String school,resultAL,higherStudies;

    public void setSchool(String inSchool){
        school=inSchool;
    }
    public void setResult(String result){
        resultAL=result;
    }

    public void setHigherStudy(String inHigherStdy){
        higherStudies=inHigherStdy;
    }

    public String getSchool(){
        return school;
    }
    public String getresult(){
        return resultAL;
    }
    public String getHigherStudy(){
        return higherStudies;
    }


}

 class factoryORstate extends building {
    private String type,size,owner;
    private int workforce;

    public void setData(){
        try{
        BufferedReader buff1 = new BufferedReader(new InputStreamReader(System.in));

        System.out.print("\nEnter data for factory/state\n");
        System.out.print("Type (facotory or state) :");
       setType(buff1.readLine());

       System.out.print("size (large, medium or small) :");
       setSize(buff1.readLine());

       System.out.print("Owners name :");
       setOwner(buff1.readLine());

       System.out.print("size of work force :");
       setWorkForce(Integer.parseInt(buff1.readLine()));




        }catch(Exception e){

        }
    }

    public void setType(String inType){
        type=inType;
    }
    public void setSize(String inSize){
        size=inSize;
    }
    public void setOwner(String inOwner){
        owner=inOwner;
    }
    public void setWorkForce(int inWorkForce){
        workforce=inWorkForce;
    }

    public String getType(){

Well ... if you take a closer look at your code, you'll see that you haven't placed your main method in the Main class, but in a 'newMain' class. your JVM is looking for the Main class in your code, but since it's not there, it runs into an exception.

Here's how to copy and paste the command prompt:
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.


Your posted code does NOT have a class named: Main.

Well ... if you take a closer look at your code, you'll see that you haven't placed your main method in the Main class, but in a 'newMain' class. your JVM is looking for the Main class in your code, but since it's not there, it runs into an exception.

Sorri.. It was a mistake.. mistake in this code but not the code that i tried to run at cmd.. I'm sorry about that.I'll edit this code..

Here's how to copy and paste the command prompt:
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.


Your posted code does NOT have a class named: Main.

Thank you for the tip.
I'm sorry about that because this is not the code I tried to run at cmd.. the original code has a class named Main..I'll post the original one.

code

import java.io.*;
import java.util.*;
 class main {


    public static void main(String[] args) {

     ArrayList<house> House = new ArrayList<house>();
        house tempHouse=new house();
        factoryORstate fac =new factoryORstate();



int input=0,nic;
String temp;
try{
        BufferedReader buff2 = new BufferedReader(new InputStreamReader(System.in));
while(true){


        System.out.print("\n\nWhat do you wanto do ?");
         System.out.print("\n Add new person ------------------ 1  ");
         System.out.print("\n view person details ------------- 2  ");
         System.out.print("\n Add new House ------------------- 3  ");
         System.out.print("\n Add new Factory/State ----------- 4  ");
         System.out.print("\n exit ---------------------------- 6  ");

       //  buff2.reset();
          temp = buff2.readLine();
          input=Integer.parseInt(temp);
         // System.out.print(input);

          switch(input){

    case 1:
       // home[0].setData();
       nic= tempHouse.setData();
        tempHouse.save(nic);
        break;

    case 2:

        System.out.print("\n Enter the NIC no of the person   : ");
        temp = buff2.readLine();
        nic=Integer.parseInt(temp);
        System.out.print(tempHouse.getDetails(nic));
      break;

    case 3:
        House.add(tempHouse);
        tempHouse.member.clear();
        break;
    case 4:
        fac.setData();
        break;


    case 6:
        System.exit(0);

    default:
        continue;

}


    }

    }catch(Exception e){
           System.out.print("\n Error--"+e.toString());
        }





    }

}


 abstract class building {

    private int buildingNo;
    private ArrayList<String> houses = new ArrayList<String>();
    private ArrayList<String> lands = new ArrayList<String>();
    private ArrayList<String> vehicles = new ArrayList<String>();

    public void setNo(int inNo){
    buildingNo=inNo;
    }
    public void setHouse(String house){
     houses.add(house);
    }

    public void setLand(String land){

        lands.add(land);
    }
    public void setVehicle(String vehi){

        vehicles.add(vehi);

    }

public int getNo(){
    return buildingNo;
}
public ArrayList getHouse(){
    return houses;
}
public ArrayList getland(){
    return lands;
}
public ArrayList getvehicle(){
    return vehicles;
}


}


class house extends building{

   // private ArrayList<person> member =new ArrayList<person>();
    private int numberOdChildren;


     Hashtable member =new Hashtable();



    public int setData(){
        int inNIC=-1;
         person tempPerson =new person();

         try{
        BufferedReader buff1 = new BufferedReader(new InputStreamReader(System.in));
        person tempPerson2 =new person();

        // System.out.print("\n\n\n\n "+tempPerson.pData.getName());
/*get personal data*/
        System.out.print("\nEnter personal data\n");
        System.out.print("Full Name  :");
        tempPerson2.pData.setName(buff1.readLine());

//        System.out.print("Date Of Birth yyyy/mm/dd :");
//        tempPerson.pData.setDateOfBirth(buff1.readLine());

        System.out.print("ID number  :");
        inNIC=Integer.parseInt(buff1.readLine());
        tempPerson2.pData.setNICno(inNIC);

        System.out.print("Contact number xxxxxxxxxx :");
        tempPerson.pData.setcontactNo(Integer.parseInt(buff1.readLine()));

        System.out.print("nGender (male/female) :");
        tempPerson.setSex(buff1.readLine());

        System.out.print("Relationship to cheif occupant :");
        tempPerson.setRelationship(buff1.readLine());

        System.out.print("DS division  :");
        tempPerson.setDivision(buff1.readLine());

        System.out.print("District  :");
        tempPerson.setDistrict(buff1.readLine());
/*get professional data*/
        System.out.print("\nEnter professional data\n");
        System.out.print("Profession  :");
        tempPerson.proData.setProfession(buff1.readLine());

         System.out.print("Salary  :");
        tempPerson.proData.setSalary(Integer.parseInt(buff1.readLine()));
/*get Educational data*/
        System.out.print("\nEnter Educational data\n");
        System.out.print("School  :");
        tempPerson.eData.setSchool(buff1.readLine());

        System.out.print("Advanced Level Results  :");
        tempPerson.eData.setResult(buff1.readLine());

        System.out.print("Details of Higher Studies  :");
        tempPerson.eData.setHigherStudy(buff1.readLine());

member.put(tempPerson2.pData.getNICno(), tempPerson2);

//buff1.close();

   }catch(IOException e){
        System.out.println("\nError--"+e.toString());
    }
         return inNIC;
    }

    void setChild(int num){
        numberOdChildren=num;
    }



    public String getDetails(int NIC){

       person tempPerson =new person();
       tempPerson=(person)member.get(NIC);

    return "name  :"+tempPerson.pData.getName()+"\n "
            + "Date Of Birth    :"+tempPerson.pData.getDateOfBirth()+"\n "
            + "ID number    :"+tempPerson.pData.getNICno()+"\n "
            + "Contact number   :"+tempPerson.pData.getcontactNo()+"\n "
            + "Gender   :"+tempPerson.getSex()+"\n "
            + "Relationship to cheif occupant   :"+tempPerson.getRelationship()+"\n "
            + "DS division  :"+tempPerson.getDivision()+"\n "
            + "District :"+tempPerson.getDistrict()+"\n "
            + "Profession   :"+tempPerson.proData.getProfession()+"\n"
            + "Salary   :"+tempPerson.proData.getSalary()+"\n "
            + "School   :"+tempPerson.eData.getSchool()+"\n "
            + "Advanced Level Results   :"+tempPerson.eData.getresult()+"\n "
            + "Details of Higher Studies    :"+tempPerson.eData.getHigherStudy()+"\n ";




}

    public void save(int NIC){

        person tempPerson =new person();
        tempPerson=(person)member.get(NIC);

        try{

          BufferedWriter buffw = new BufferedWriter(new FileWriter("d:\\data.txt",true));
          buffw.write(getDetails(NIC));
          buffw.newLine();
          buffw.close();

        }catch(Exception e){
        System.out.print("Error-- "+e.toString());
        }


    }

}

 class person {

    private String relationshipToChiefOccupant;
    private String sex,DSdivision,district;
    personalData pData = new personalData();
    professionalData proData = new professionalData();
    educationalData eData =new educationalData();

public void setData(String relationship,String inSex,String inDivision,String inDistrict){
    relationshipToChiefOccupant=relationship;
    sex = inSex;
    DSdivision=inDivision;
    district=inDistrict;

}
public void setRelationship(String relationship){

     relationshipToChiefOccupant=relationship;
}

public void setSex(String inSex){
    sex = inSex;
}

public void setDivision(String inDivision){
    DSdivision=inDivision;
}

public void setDistrict(String inDistrict){
     district=inDistrict;
}

public String getRelationship(){
    return relationshipToChiefOccupant;
}

public String getSex(){
    return sex;
}

public String getDivision(){
    return DSdivision;
}

public String getDistrict(){
    return district;
}




}


 class personalData {
    private String name,dateOfBirth;
    private int NICno,contactNo;

    public void setName(String inName){
        name=inName;
    }
    public void setDateOfBirth(String dob){
        dateOfBirth=dob;
    }
    public void setNICno(int NIC){
        NICno=NIC;
    }
    public void setcontactNo(int contact){
        contactNo=contact;
    }

    public String getName(){
        return name;
    }
    public String getDateOfBirth(){
        return dateOfBirth;
    }
    public int getNICno(){
        return NICno;
    }
    public int getcontactNo(){
        return contactNo;
    }

}


 class professionalData {
    private String profession;
    private int salary;

    public void setProfession(String inprofession){
        profession=inprofession;
    }

    public void setSalary(int inSalary){
        salary=inSalary;
    }

    public String getProfession(){
        return profession;
    }
    public int getSalary(){
        return salary;
    }

}

 class educationalData {

    private String school,resultAL,higherStudies;

    public void setSchool(String inSchool){
        school=inSchool;
    }
    public void setResult(String result){
        resultAL=result;
    }

    public void setHigherStudy(String inHigherStdy){
        higherStudies=inHigherStdy;
    }

    public String getSchool(){
        return school;
    }
    public String getresult(){
        return resultAL;
    }
    public String getHigherStudy(){
        return higherStudies;
    }


}

 class factoryORstate extends building {
    private String type,size,owner;
    private int workforce;

    public void setData(){
        try{
        BufferedReader buff1 = new BufferedReader(new InputStreamReader(System.in));

        System.out.print("\nEnter data for factory/state\n");
        System.out.print("Type (facotory or state) :");
       setType(buff1.readLine());

       System.out.print("size (large, medium or small) :");
       setSize(buff1.readLine());

       System.out.print("Owners name :");
       setOwner(buff1.readLine());

       System.out.print("size of work force :");
       setWorkForce(Integer.parseInt(buff1.readLine()));




        }catch(Exception e){

        }
    }

    public void setType(String inType){
        type=inType;
    }
    public void setSize(String inSize){
        size=inSize;
    }
    public void setOwner(String inOwner){
        owner=inOwner;
    }
    public void setWorkForce(int inWorkForce){
        workforce=inWorkForce;
    }

    public String getType(){
        return type;
    }
    public String getSize(){
        return size;
    }
    public String getOwner(){
        return owner;
    }
    public int getWorkForce(){
        return workforce;
    }

}

Error

C:\Users\SUDHEERA\Desktop\java>javac main.java
Note: main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

C:\Users\SUDHEERA\Desktop\java>java main
Exception in thread "main" java.lang.NoClassDefFoundError: main
Caused by: java.lang.ClassNotFoundException: main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: main. Program will exit.

C:\Users\SUDHEERA\Desktop\java>

Edited 5 Years Ago by baby_c: n/a

Do a dir command after the javac compile step to show what files are in the directory.
Is the CLASSPATH environment variable set? Does it have a . in it?
If not either add one to it or use the -cp . option for java:
java -cp . main

BTW Naming conventions for classes use Uppercase for the first letter: Main

Edited 5 Years Ago by NormR1: n/a

Do a dir command after the javac compile step to show what files are in the directory.
Is the CLASSPATH environment variable set? Does it have a . in it?
If not either add one to it or use the -cp . option for java:
java -cp . main

BTW Naming conventions for classes use Uppercase for the first letter: Main

Thank you for helping.. It worked.. But can I make this code to work just entering java Main at cmd ??

and ... case sensitivity is in play: main is not the same as Main

Thank you friend.. I got it.. :)

This question has already been answered. Start a new discussion instead.