1
votes

To better organize my classes, I made a few sub-packages (that is an extension in the package's hierarchical name structure).

But to my surprise I have been getting an R cannot be resolved to a variable for like every resource I am trying to use from this project's R file.

The Eclipse's quick fixes options do give the option of importing the particular R file for the package (which contains the sub-packages), But the question is that in the package that I created in the Eclipse's New Application Project wizard, I did not need to import the R file at all, and I always thought it contained the resources for this entire project.

But now after creating sub-packages, I need to import it. SO asking out of curiosity, since a sub-package is nothing (in Java) but an extension in the hierarchical name structure of the package itself (reference), then why doesn't the R file automatically get included in the sub-packages?

1
Downvoter: I need to know why am I getting a downvote on this, please? - Solace
I am not the "downvoter" but I think because they probably think it's a bad question because it's solved so easily. I'm still a beginner to Android so yeah... - hsirkar
There is no such thing as "sub-packages" as each package is its own namespace. my.project.package is separate from my.project.package.hello they are not the same thing, but they may be shown in hierarchy for convenience of viewing. - Pranav A.

1 Answers

1
votes

R is just a class like any other class (except that Eclipse creates it for you and keeps it updated with your resource IDs).

It is contained in a package - like every other class.

If you want to use it from a different package, you must import it or use the fully qualified name - like you would with any other class.