1 Reply Latest reply on Jun 23, 2010 1:05 PM by 800387

    How to create package class ..

      Dear firend,

      I have created the packge file under /home/in/package/Time1.java


      package in.package;

      public class Time1 {

      public static String name="Package Testing";

      public void assign_name(String val) {


      public String get_name() {
      return name;

      public static void main(String args[]) {

      Time1 obj=new Time1();


      Then I have tried to access this package file from home directory.

      import co.in.bksys.packaging.Time1;

      *public class package_test {*

      * public static void main(String args[]) {*

      //in.package.Time1 time_test=new in.package.Time1();
      Time1 time_test=new Time1();
      * time_test.assign_name("Leslie Samuel");*
      * String my_name=time_test.get_name();*
      * System.out.println(my_name);*


      I have compiled this file from the home direcory.

      *$ javac -classpath in/package/ package_test.java*

      It was displayed this below error:

      * package_test.java:1: package in.package does not exist*
      import in.package.Time1;
      * ^*
      package_test.java:8: cannot access Time1
      bad class file: in/package/Time1.java
      file does not contain class Time1
      Please remove or make sure it appears in the correct subdirectory of the classpath.
      * Time1 time_test=new Time1();*
      * ^*
      *2 errors*

      but if i used this below line in the package_test.java file insted of using this Time1 time_test=new Time1(); .
      It will work perfectly.

      in.package.Time1 time_test=new in.package.Time1();

      I know that its expecting some format of class file like , in.package.Time1.class inside the in/package/ directory.
      It wasn't there so displayed this error.

      How to create this knid of class file to appropriate directory ?
      How to make my program execute without giving full package name like , in.package.Time1 time_test=new in.package.Time1();  ?

      Thank you.