-1
setContentView(R.layout.activity_main);

gives me the error message in the title. I've tried to delete and renerate R, clean the project and nothing. activity_main is right there registered in R. I have no problems in /res, no red crosses or problems in the problems tab. There's no import android.R in my Activity. I've tried everything I could find here and nothing. "R cannot be resolved to a variable"?

What's going on?

Community
  • 1
  • 1
Thiago
  • 746
  • 1
  • 10
  • 22

1 Answers1

2

The simplest coding pattern, and what you will see most examples do, is to have the activities (and any other resource-dependent classes) reside in the Java package declared in the manifest's package attribute. That way, R is auto-imported, and you don't have to think about it.

You are welcome to have R references in other packages, but you will have to import the R from the manifest's package (e.g., import com.commonsware.sample.R;).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • And you still went further and probably prevented a future episode of me for 30 minutes asking myself where the mistake is. Thanks again for this :) – Thiago Jul 22 '13 at 01:14