• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Default package try to access user define package

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yesterday is saw the code from the thread of this forum and try to compile it
but i don't know why this one is compile error



when i first time see it. I guess that that line will compile successfully. because i've just import that class.
and the tiger access modifier is public.

can somebody please help me with this one ?
is there's something i miss with a package access ??
 
Welly Tambunan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but then when i modified the code into somthing like this it works...
i'm still confuse.



 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I think this problem might be due to the directory structure. When you didn't put the package statement in the PkgAccess2.java, where did you put it??

There are two ways that this could have been done, 1. with the package statement in PkgAccess2.java and 2. with the package statement in PkgAccess2.java. Lets see the directory structure for both the solutions

1.


2.


[edit: corrected name of PkgAccess.java]
 
Welly Tambunan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot Ankit.

before compiling PkgAccess1.java my directory structure is like this :


and then i compile from cmd (Windows) with a command



the result is


but when i'm trying to compile the PkgAccess2.java with
or


the result is compile error. cannot access PkgAccess.
why this happen ?
I don't understand..
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all sorry I used incorrect file names in my previous post. I'm correcting it.

Well welly, the way you are trying to accomplish this task will lead into problems. You are placing .java files in the incorrect directory structure. With that, you'll get this kind of error on compiling PkgAccess2.java



That will happen because javac will find PkgAccess.java in the wrong directory structure. You'll have to move PkgAccess.java to the correct directory structure to let it compile. You can search the forum and you'll find that earlier too people had the same problem...
 
Welly Tambunan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:
That will happen because javac will find PkgAccess.java in the wrong directory structure. You'll have to move PkgAccess.java to the correct directory structure to let it compile. You can search the forum and you'll find that earlier too people had the same problem...



ooo.. thank you ankit.
i moved the PkgAccess.java and PkgAccess2.java is successfully compiled.

thanks a lot. once again thanks a lot for your time.
 
Come have lunch with me Arthur. Adventure will follow. This tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic