• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Package directory structure

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have heard that a package can have any name. But when I try to create a package such as "practice1.self" I get an error stating: The declared package "practice1.self" does not match the expected package "package1"

Do the package names have a dependency on the directory structure? How can I correct this error?
 
Greenhorn
Posts: 29
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are probably trying to create a class inside practice1 directory and putting package name practice1.self

You should have a nested directory inside practice1 as "self" where you can have a class with "package practice1.self"

Hope the above explains the directory structure that needs to be followed.

Am not very sure if this is full and final relation between directory and package, but should work well.
 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please post your directory structure and your code so that we can get it more neatly
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anchit Herredia wrote:Do the package names have a dependency on the directory structure? How can I correct this error?



Yes they have a dependency.
 
Anchit Herredia
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

mohamed sanaullah wrote:

Anchit Herredia wrote:Do the package names have a dependency on the directory structure? How can I correct this error?



Yes they have a dependency.




You should have a nested directory inside practice1 as "self" where you can have a class with "package practice1.self"



Are you sure this is correct? I'm trying to use Eclipse to create this kind of package structure but it doesn't create. Both package1 and self get created at the same level of hierarchy.

Never mind about answering this. I got the answer. For some weird reason you need to create a new Folder in Eclipse. If you want to create nested packages just keep creating folders and then create the Java files inside them. I'm not sure why the behaviour is like this. Well, Thanks for your answers.

Also, here is further information to anyone wanting to read more on this: http://www.webdeveloper.com/forum/showthread.php?t=71195
Eclipse makes it compulsory that the package structure should match the folder structure for the source. IntelliG doesn't have this restriction. And in both cases what really matters is that the compiled classes will have to follow the folder hierarchy according to their packages.
 
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic