Home » Newcomers » Newcomers » Classes Don't Show Up For Importing
Classes Don't Show Up For Importing [message #168027] |
Tue, 29 August 2006 03:19  |
Eclipse User |
|
|
|
Originally posted by: hal.thresholddigital.com
I'm new to using a hierarchy for Java packages. (I'm self taught, so there
are things that seem standard that I'm still getting used to.) In my case,
I've just started adapting several of my projects to fit in this kind of
structure. I just created a new project that will included several other
projects that are tied together. I've got the following packages in it:
com.thresh.util
com.thresh.comm
com.thresh.editor
com.thresh.gui
This package is set up in a new directory so I can, one by one, import my
other projects into it without messing up what has been working all along.
I tried to add two classes to com.thresh.util. Originally, while in the
Package Explorer, I right clicked on the classes in another project,
picked "Copy" to copy them, then right clicked on com.thresh.util and
picked "Paste." The two classes were pasted into com.thresh.util and the
line "package com.thresh.util;" was added at the start of my class. So far
so good.
The problem came when I tried to use those classes in a class in
com.thresh.gui. The two classes (in util) are StringHashMap and TNUtil. I
added:
import comp.thresh.util.TNUtil.
I kept getting the message, over and over, no matter what I tried, that
com.thresh.util.TNUtil was not visible. I finally had to rename TNUtil,
right click on com.thresh.util, create a new class TNUtil, then copy the
contents of the first original TNUtil into the new class. When I did that,
the class was visible and able to be imported. Even using CTRL-SHIFT-O to
organize my imports would automatically add the import for that class.
Since I had so much of a problem with that, to add classes to
com.thresh.comm, I right clicked on it and clicked "import." I imported
the files I needed through the file system, and the package line was not
automatically added to those files. I added the package line, but then the
classes were not able to be imported because they were not visible.
Basically, it seems like no matter how I add classes to a package, some are
copied or imported in appropriately, but many are not.
How do I take a package that's part of one project and copy it or import it
into another project so I can be sure it is visible for other classes that
want to use it -- without going through creating a file and cutting and
pasting the text itself? (I'm using 3.2.0 on Ubuntu Linux.)
Thanks for any help on this!
Hal
|
|
|
Re: Classes Don't Show Up For Importing [message #168093 is a reply to message #168027] |
Tue, 29 August 2006 07:49   |
Eclipse User |
|
|
|
Originally posted by: jochen.wuttke.gmx.de.invalid
Hal Vaughan wrote:
> I'm new to using a hierarchy for Java packages. (I'm self taught, so there
> are things that seem standard that I'm still getting used to.) In my case,
> I've just started adapting several of my projects to fit in this kind of
> structure. I just created a new project that will included several other
> projects that are tied together. I've got the following packages in it:
>
> com.thresh.util
> com.thresh.comm
> com.thresh.editor
> com.thresh.gui
>
> This package is set up in a new directory so I can, one by one, import my
> other projects into it without messing up what has been working all along.
> I tried to add two classes to com.thresh.util. Originally, while in the
> Package Explorer, I right clicked on the classes in another project,
> picked "Copy" to copy them, then right clicked on com.thresh.util and
> picked "Paste." The two classes were pasted into com.thresh.util and the
> line "package com.thresh.util;" was added at the start of my class. So far
> so good.
>
> The problem came when I tried to use those classes in a class in
> com.thresh.gui. The two classes (in util) are StringHashMap and TNUtil. I
> added:
>
> import comp.thresh.util.TNUtil.
>
> I kept getting the message, over and over, no matter what I tried, that
> com.thresh.util.TNUtil was not visible. I finally had to rename TNUtil,
> right click on com.thresh.util, create a new class TNUtil, then copy the
> contents of the first original TNUtil into the new class. When I did that,
> the class was visible and able to be imported. Even using CTRL-SHIFT-O to
> organize my imports would automatically add the import for that class.
>
> Since I had so much of a problem with that, to add classes to
> com.thresh.comm, I right clicked on it and clicked "import." I imported
> the files I needed through the file system, and the package line was not
> automatically added to those files. I added the package line, but then the
> classes were not able to be imported because they were not visible.
>
> Basically, it seems like no matter how I add classes to a package, some are
> copied or imported in appropriately, but many are not.
>
> How do I take a package that's part of one project and copy it or import it
> into another project so I can be sure it is visible for other classes that
> want to use it -- without going through creating a file and cutting and
> pasting the text itself? (I'm using 3.2.0 on Ubuntu Linux.)
This all sounds a bit like you didn't use the "public" modifier for your
classes. Once you use packages, only classes that are "public" can be imported
(and used) in other packages.
For the moving/copying: If you have all your projects that use the classes you
want to move inside one workspace, then you can use Eclipses "Move"
refactoring. That should take care of all proper renaming and warn you if you
get visibility issues.
Jochen
|
|
|
Re: Classes Don't Show Up For Importing [message #168174 is a reply to message #168093] |
Tue, 29 August 2006 11:51  |
Eclipse User |
|
|
|
Originally posted by: hal.thresholddigital.com
Jochen wrote:
> Hal Vaughan wrote:
>> I'm new to using a hierarchy for Java packages. (I'm self taught, so
>> there
>> are things that seem standard that I'm still getting used to.) In my
>> case, I've just started adapting several of my projects to fit in this
>> kind of
>> structure. I just created a new project that will included several other
>> projects that are tied together. I've got the following packages in it:
>>
>> com.thresh.util
>> com.thresh.comm
>> com.thresh.editor
>> com.thresh.gui
>>
>> This package is set up in a new directory so I can, one by one, import my
>> other projects into it without messing up what has been working all
>> along.
>> I tried to add two classes to com.thresh.util. Originally, while in the
>> Package Explorer, I right clicked on the classes in another project,
>> picked "Copy" to copy them, then right clicked on com.thresh.util and
>> picked "Paste." The two classes were pasted into com.thresh.util and the
>> line "package com.thresh.util;" was added at the start of my class. So
>> far so good.
>>
>> The problem came when I tried to use those classes in a class in
>> com.thresh.gui. The two classes (in util) are StringHashMap and TNUtil.
>> I added:
>>
>> import comp.thresh.util.TNUtil.
>>
>> I kept getting the message, over and over, no matter what I tried, that
>> com.thresh.util.TNUtil was not visible. I finally had to rename TNUtil,
>> right click on com.thresh.util, create a new class TNUtil, then copy the
>> contents of the first original TNUtil into the new class. When I did
>> that,
>> the class was visible and able to be imported. Even using CTRL-SHIFT-O
>> to organize my imports would automatically add the import for that class.
>>
>> Since I had so much of a problem with that, to add classes to
>> com.thresh.comm, I right clicked on it and clicked "import." I imported
>> the files I needed through the file system, and the package line was not
>> automatically added to those files. I added the package line, but then
>> the classes were not able to be imported because they were not visible.
>>
>> Basically, it seems like no matter how I add classes to a package, some
>> are copied or imported in appropriately, but many are not.
>>
>> How do I take a package that's part of one project and copy it or import
>> it into another project so I can be sure it is visible for other classes
>> that want to use it -- without going through creating a file and cutting
>> and
>> pasting the text itself? (I'm using 3.2.0 on Ubuntu Linux.)
>
> This all sounds a bit like you didn't use the "public" modifier for your
> classes. Once you use packages, only classes that are "public" can be
> imported (and used) in other packages.
That's it! I checked the classes and compared the ones in the new project
with the old project and that's the difference.
> For the moving/copying: If you have all your projects that use the classes
> you want to move inside one workspace, then you can use Eclipses "Move"
> refactoring. That should take care of all proper renaming and warn you if
> you get visibility issues.
I hadn't tried that. For now I want the old projects to work for a while,
so I don't want to just move classes. If the Refactor menu had a Copy
option, I'd use that. Now I see that as I rebuild the old projects as one
project with a hierarchy, I'll have to make a few changes, but most of that
will be taken care of by making sure the classes are public and using
CTRL-SHIFT-O to add the needed imports.
I figure I'm also going to have to learn Ant and how to use Build features,
since I'm still popping over to a console and using javac. (As I said, I'm
self taught, so I know I'm not using a lot of the features of Eclipse, but
it takes time to get used to everything and, being self taught, I've missed
a lot of things I think I would have been shown if I had taken classes.)
Thanks for the help!
Hal
|
|
|
Goto Forum:
Current Time: Wed Jun 04 11:35:23 EDT 2025
Powered by FUDForum. Page generated in 0.08397 seconds
|