开发者

Java package convention

I'm developing an Android project which currently has 4 packages:

com.myapp.app.activities
com.myapp.app.db
com.myapp.app.ws
com.myapp.app.utils

Would I be able to create an additional package which is just

com.myapp.app

?

Eclipse 开发者_C百科isn't letting me create this package. It tells me a package with this name already exists.

If I start a new project and create a package called "com.testing.app" and then create a new package called "com.testing.app.activities" afterward, it works fine.

For Android developers:

What I'm wanting to do is extend the Application class and have it in a separate package. Suppose com.myapp.app can't be used, what's a good name for this new package?


Eclipse won't let you create this package because it already exists.

Packages in Java are represented in the filesystem as hierarchical folders: com.myapp.app.activities is in the com/myapp/app/activities folder. com/myapp/app already exists, so you can't create this package.

In Eclipse, juste create a new class, and in the "Package" section, precise you want to create it in the com.myapp.app package. This should work.


The package com.myapp.app already exists. You can create a class named com.myapp.app.MyClass, you'll see it right in the app package.

Another thing you can do is changing the layout of your packages from a flat layout to a hierarchical layout :

Java package convention


Resources :

  • help.eclipse.org : Project Explorer view


Eclipse by default hides empty packages. In the package explorer view, click at the small arrow in the right top: View Menu. Choose Customize View. In the Filters tab you need to uncheck Empty packages. Now empty packages will be visible in the package explorer.

Java package convention


It would appear that if I manually place a file into the directory and refresh the package explorer in Eclipse, the new com.myapp.app package appears

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜