• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

an unbelievable question about import!!!

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
should I always supply source code files to develper who use my libs?
 
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.*;" ???
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the Beginners forum...
 
What's a year in metric? Do you know this metric stuff tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic