• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

an unbelievable question about import!!!

 
Mike Lin
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
at the directory of c:\m
compile file A.java

then I turn to directory c:\n to compile file Test.java

compile failed ,messages:
Test.java:12: cannot resolve symbol
symbol : constructor A ()
location: class A
A i= new A();
^
1 error
BUT ,when I change the first line of Test.java to
"import p.A;"
compile success!!!
 
Serghei Jelauc
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You must save A.java in the folder with mane "p" because you indicated "package p".
 
Mike Lin
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
should I always supply source code files to develper who use my libs?
 
Kishore Dandu
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as you are providing the jar of the package you don't need to provide the source code to the other user of your classes.
 
Jon Egan
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the topic seems to have changed here, mid-thread.... I have a guess as to the problem with the first post. Was it that there was another class "A" (say x.A) that was found in the classpath, and overrriding the class p.A? And, that x.A did not have a no-arg constructor?
Is this maybe why the topic changed to jars? was x.A in a jar that was in the classpath before c:\ ?
copy/pasted your code, in exactly the same directories you specified, mine won't compile either way. Except mine complains it can't find the class A, where yours seems to have a problem only with the constructor in particular.
If that's not it, I'd like to hear....
-- Jon
 
Mike Lin
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,Jon
I have set the "classpath" to c:\m
 
Mike Lin
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when does class-loader needs java source files?
what 's the difference between import p.* and import p.A according to code above.
 
Mike Lin
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find copy source file to c:\m cannot solve the problem!!!
555555555555555
HELP!!!
"import p.A" is ok.
What wrong with " import p.*;" ???
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Beginners forum...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic