0

I am a computer science student and I'm trying to teach myself Android development using Android's 'Getting Started Guide.' However, on the page 'Starting An Activity' ( http://developer.android.com/training/basics/activity-lifecycle/starting.html ) I get errors on both of the following lines of code samples:

setContentView(R.layout.main_activity);

and

mTextView = (TextView) findViewById(R.id.text_message);

Specifically on .main_activity and .text_message. It cannot be resolved to R.id and I am not allowed to modify this file. I'm strictly going by the Getting Started Guide here. Didn't know if anyone else had this problem or know where I borked on this. Thanks.

Barret
  • 1
  • 1
    probably this http://stackoverflow.com/questions/2483732/r-id-cannot-be-resolved – fersarr Dec 10 '12 at 22:56
  • 1
    or this http://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error – fersarr Dec 10 '12 at 22:56
  • Something is preventing the R file from being built... Sadly there are a lot of reason why this might happen ([R cannot be resolved - Android error](http://stackoverflow.com/q/885009/1267661)). If you are using Eclipse, start in the Problems window, fix all of the _other_ errors, and rebuild your project. – Sam Dec 10 '12 at 22:57
  • first remove `android.R.*` if you have in import statements and then press `CTRL+SHIFT+O ` from keyboard for importing your on project R. i not solved then first refresh your project from right click on project and then clean your project from `Project->Clean..` from eclipse File menu – ρяσѕρєя K Dec 10 '12 at 22:58

1 Answers1

0

Right click on R.java from the project, and delete it. Rebuild the project. It should work.

Durairaj Packirisamy
  • 4,635
  • 1
  • 21
  • 27
  • Thanks for the quick answers. Tried all the recommendations and no success. When I look in the R.java file, `text_message` does not exist in `id` and `main_activity` does not exist in `layout`. Even after cleaning the project, deleting the R.java file, and rebuilding the project. – Barret Dec 10 '12 at 23:10
  • have you copied the resource xml in your project? Do you have the complete project or only .java files? – Durairaj Packirisamy Dec 10 '12 at 23:12
  • Is the resource XML the same as the AndroidManifest.xml? Or is there actually a resource.xml file? – Barret Dec 10 '12 at 23:15
  • I think you do not have the layout files which are referred in your code. Why don't you start with http://developer.android.com/training/basics/firstapp/creating-project.html – Durairaj Packirisamy Dec 10 '12 at 23:22
  • I'll take another look. I went through that section and made the little baby app and got it running on my phone properly. I'll look again though and see if there's something I missed and report back. – Barret Dec 10 '12 at 23:28
  • Oh, I figured it out. I need to manually add those attributes to my layout/activity_main.xml file. I was under the impression I was still being baby-stepped through this process, but I needed to generate those myself. Like I said, I'm totally green with Android development. Thanks for all the help. – Barret Dec 10 '12 at 23:43