3

I'm running through the notepad exercises on the android dev website, currently working on exercise (found here).

I came to the end of the tutorial and found that I had several errors in the main two java files regarding R file relations, such as setContentView(R.layout.notes_list); and menu.add(0, INSERT_ID,0, R.string.menu_insert);

I've tried cleaning and re-genning R.java to no avail.

These also occur in the solution for the exercise so I think they are deliberate mistakes, or something with my eclipse, but I can't seem to fix them, any help would be great thanks!

Arpit
  • 6,212
  • 8
  • 38
  • 69

5 Answers5

7

Do you have the layout notes_list.xml in your layout folder? Do you have a string by the name of menu_insert in your strings.xml? This might be the issue, because I think they don't give EVERYTHING in the tutorial... They do have them in the solution :

<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<ListView android:id="@+id/android:list" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:id="@+id/android:empty" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/no_notes"/>
</LinearLayout>

in strings.xml in values folder :

<string name="menu_insert">Add Note</string>
Sephy
  • 50,022
  • 30
  • 123
  • 131
  • The short answer is yes to all the above –  Jul 23 '10 at 17:04
  • 9
    Then, try to check the imports at the top of your class, sometimes this dumb Eclipse imports the R class from the android package and stops using yours. – Sephy Jul 23 '10 at 17:24
  • Haha great thats sorted it, guess I should have spotted that! I thought it was importing mine but thanks, that has fixed it. Im not a huge fan of Eclipse. Do you know how well the netbeans plugin for android performs? –  Jul 23 '10 at 17:43
  • No idea, I've only been using Eclipse. Always worked properly for me. And if not, there is plentiful of doc and forum to find answers – Sephy Jul 23 '10 at 18:34
5

I think you might have to be careful about how you use the ctrl-shift-O command (to auto-insert the "import" statements at the top of the file). It could be that you get the "import android.R;" statement as a "bonus". I commented-out the "import android.R;" statement, and everything was fine.

Andrew Jens
  • 1,032
  • 15
  • 16
3

Yeah, main problem is that Eclipse importing android.R, when ctrl+shift+o pressed. Another way to fix problem is declaring import with full path:

import com.android.demo.notepad2.R;
Valin
  • 2,285
  • 1
  • 15
  • 10
0

You should check to see that you've added an id to your LinearLayout in whatever layout xml file you're using. If that's the case, then you should look for something syntactically wrong that would prevent the R file from being rebuilt.

Something like:

android:id="@+id/linearLayout"
Euler Geek
  • 121
  • 1
  • 8
0

While hardcoding string, don't use space in both .xml files. i.e @string/a b c is wrong try @string/a_b_c

Arpit
  • 6,212
  • 8
  • 38
  • 69
shon
  • 1