-1

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?

Community
  • 1
  • 1
Solace
  • 8,612
  • 22
  • 95
  • 183
  • Downvoter: I need to know why am I getting a downvote on this, please? – Solace Jan 08 '15 at 01:22
  • 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 Jan 08 '15 at 03:07
  • 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. Sep 04 '17 at 15:04

1 Answers1

1

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.

user253751
  • 57,427
  • 7
  • 48
  • 90