import package
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: import package

Hybrid View

  1. #1
    Join Date
    Nov 2010
    Posts
    146

    import package

    Hello all

    I am a student and I am new to Java. I have created a simple Java program. We have been given a package to import into the program we have developed. The classes of the package are stored in a folder called "pack" which is placed inside project folder called "tictactoe". The example program we were given imports the package as follows and it works fine.

    import pack.*;

    Is it that simple or do I need to do more.

    It gives me the error "The import pack cannot be resolved"

    Thanks

  2. #2
    Join Date
    Mar 2010
    Posts
    16

    Re: import package


  3. #3
    Join Date
    Nov 2010
    Posts
    146

    Re: import package

    Yes but are these not two different websites?

  4. #4
    Join Date
    Dec 2012
    Location
    Danang, Viet Nam
    Posts
    9

    Re: import package

    Firstly, you have to include jar file that containing your pakage in your project. In Eclipse is setting build path.
    Then is using import statement to import the needed class.
    By the way, I recommened that you shouldn't import like that : import package_example.*
    Should importing exactly what classes you need, e.g : import package_example.Class_A;

  5. #5
    Join Date
    Nov 2010
    Posts
    146

    Re: import package

    Thank you Phillip

    The package "pack" is just a folder containing files with .java and .class extensions. We are asked to create a program that contains four classes which should use the files inside the folder called "pack" by importing the "pack" i-e

    import pack.*;

    It does work for the example program given by the teacher but not for me. I am sure I am missing something. Could you please tell me the the way it is set in the build path?

  6. #6
    Join Date
    Dec 2012
    Location
    Danang, Viet Nam
    Posts
    9

    Re: import package

    Hi gulHK,

    If you having java source code files, just copy them into your package.
    e.g : in package 'pack' already contains java source code like this : LibraryA.java, then just copy this file into your package. And using import statement like this in your code : import your_package.LibraryA;

    You can set build path in Eclipse , if the classes you intend to 'import' have already packaged in jar file.

  7. #7
    Join Date
    Nov 2010
    Posts
    146

    Re: import package

    Hello Phillp

    I have copied the .java classes into my project and it works fine. I do not need to import them any more. But I still cannot use the .class files and it gives me the same error. This is how I import them

    import pack.reader.class

    Is this correct?

  8. #8
    Join Date
    Dec 2012
    Location
    Danang, Viet Nam
    Posts
    9

    Re: import package

    Why you have to need to import class files?
    If you already having java files of those classes, just copy them to your program and use.

  9. #9
    Join Date
    Dec 2012
    Location
    Danang, Viet Nam
    Posts
    9

    Re: import package

    Quote Originally Posted by gulHK View Post
    Hello Phillp

    I have copied the .java classes into my project and it works fine. I do not need to import them any more. But I still cannot use the .class files and it gives me the same error. This is how I import them

    import pack.reader.class

    Is this correct?
    Hi gulHK,

    You dont need to import java class for using, because that the class that be used in your program ( e.g Main.java ) is located the same package (folder) with Main.java. If it's belong to another package, you have to import in Main.java to use.

  10. #10
    Join Date
    Nov 2010
    Posts
    146

    Re: import package

    I have just tried the program without the .class files and copying only the .java ones and it worked. You were right and thanks a ton for that

  11. #11
    Join Date
    Dec 2012
    Location
    Danang, Viet Nam
    Posts
    9

    Re: import package

    Hi gulHK,
    You are welcome.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center