This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes 'import' question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark " Watch " New topic
Author

'import' question

Paul Keohan
Ranch Hand

Joined: Mar 15, 2000
Posts: 411
Some code I was updating wouldn't compile when I referred to a class that was in another package - even though I imported this package with a '*' to include all classes. Only when I specified the class in the import statement, did it compile.
What could be the reason for this? The '*' always seemed to work before.
Thanks.
Paul
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
What error message did the compiler display?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2833
    
  11

In particular, it could be that you included two packages (using *) that both contained a class by that name. The compiler would complain about an ambiguous class reference, rather than a missing class. Is that the error you got?
Paul Keohan
Ranch Hand

Joined: Mar 15, 2000
Posts: 411
There is definitely no other class of this name anywhere. The compiler gives an error saying it can't see one of the methods in the class (as though I'm referring to a non-existant method). The method is a static one for getting one instance of the class. It definitely exists.
Paul
Ellen Zhao
Ranch Hand

Joined: Sep 17, 2002
Posts: 581
I assume you are using a windows box, how did you compile it? Dos console or with some IDE? And, how many JDKs are there in your box? Earlier I had JDK 1.3, then updated to 1.4.1, but the 1.3 wasn't cleanly removed, that caused a lot of problems.
[ February 17, 2003: Message edited by: Ellen Zhao ]
Paul Keohan
Ranch Hand

Joined: Mar 15, 2000
Posts: 411
With the JCreator IDE. In hindsight I think it may have something to do with their private constructors. I don't what but maybe something.
Ellen Zhao
Ranch Hand

Joined: Sep 17, 2002
Posts: 581
Oops...JCreator, it kept frustrating me because of the setting of environment variable ( but It's still the only IDE I am frequently using to edit source code -- but not for compiling ). What I can tell you is that if you use JCreator, your settings of classpath in the windows environment variables seems quite meaningless, you have to tell JCreator where to find the classes explicitly. When it comes to compile, I usually turn to dos console and leave JCreator away. I believe there exists some solution, but I don't know...see if there is any JCreator expert here...I want to know this too, will turn to this thread again.

Regards,
Ellen
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

I ran across something quirky with 1.1.8 and 1.2.2, and 1.3.1 as well (but the error message was different). Could this be the problem:
ARGH! Package problem while using *
Paul Keohan
Ranch Hand

Joined: Mar 15, 2000
Posts: 411
Yes, this is the exact problem I'm having. There was no real answer provided was there? I know I had compiled my 'importee' class numerous times before trying to compile the 'importer' class - so it wasn't an old class or mismatched method problem. The only way I could get around it was to import the specific class name.
Paul Keohan
Ranch Hand

Joined: Mar 15, 2000
Posts: 411
Is it something to do with static methods? That's something your sample code and my code have in common.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Yes, there is an answer provided. Read the thread again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 'import' question
 
Similar Threads
Regarding "javac" compiler
Help on Packages!!
error importing java.rmi.Registry and Server
Default and Subpackage
import java.*; ????