-
December 27th, 2012, 09:25 AM
#1
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
-
December 27th, 2012, 11:11 AM
#2
-
December 27th, 2012, 11:15 AM
#3
Re: import package
Yes but are these not two different websites?
-
December 27th, 2012, 11:01 PM
#4
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;
-
December 28th, 2012, 12:18 AM
#5
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?
-
December 28th, 2012, 01:11 AM
#6
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.
-
December 28th, 2012, 02:39 AM
#7
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?
-
December 28th, 2012, 02:45 AM
#8
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.
-
December 28th, 2012, 02:53 AM
#9
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
-
December 28th, 2012, 02:59 AM
#10
Re: import package
Hi gulHK,
You are welcome.
-
December 28th, 2012, 03:03 AM
#11
Re: import package
Originally Posted by gulHK
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|