Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

'import' question

 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What error message did the compiler display?
 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 581
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 581
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it something to do with static methods? That's something your sample code and my code have in common.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, there is an answer provided. Read the thread again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic