How to create package class

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: How to create package class

  1. #1
    Join Date
    Apr 2010

    How to create package class

    Dear firend,

    I have created the packge file under /home/in/package/
    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.
    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();
    I have compiled this file from the home direcory.

    $ javac -classpath in/package/

    It was displayed this below error:
    ========================= package in.package does not exist
    import in.package.Time1;
    ^ cannot access Time1
    bad class file: in/package/
    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 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.
    Last edited by Hack; 06-23-2010 at 07:39 AM. Reason: Added Code Tags

  2. #2
    Join Date
    Jul 2005
    SW MO, USA
    In you need an import in.package.Timer;
    You don't show it and then you do show it?

    When compiling package_test, the class path should point to the folder where the in folder is. IE at the start of the package path.

  3. #3
    Join Date
    Apr 2007
    Sterling Heights, Michigan
    Does this help at all?

  4. #4
    Join Date
    Apr 2010
    Thanks You so much norm . Now its working.

Similar Threads

  1. How to Create Forms Class in C#?
    By Complete in forum .NET
    Replies: 2
    Last Post: 04-18-2010, 01:09 PM
  2. Help with Error in class
    By velkropie in forum Java
    Replies: 5
    Last Post: 03-24-2007, 11:09 AM
  3. Getting a GUI to function
    By Eric in forum Java
    Replies: 1
    Last Post: 11-27-2001, 06:53 AM
  4. Abstract class
    By Manika in forum Java
    Replies: 1
    Last Post: 09-06-2000, 01:13 AM
  5. Create Multiple Instances of Class at Runtime
    By Eric Jenkins in forum authorevents.appleman
    Replies: 1
    Last Post: 04-13-2000, 10:23 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
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center