0

I am very new to android development with eclipse, and I encounter dozen of errors and problems. Here is the next one:

I am following a tutorial to learn android development on eclipse. I was following the example here to include actions xml (file res/menu/main_activity_actions.xml):

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- Search, should appear as action button -->
    <item android:id="@+id/action_search"
          android:icon="@drawable/ic_action_search"
          android:title="@string/action_search"
          android:showAsAction="ifRoom" />
    <!-- Settings, should always be in the overflow -->
    <item android:id="@+id/action_settings"
          android:title="@string/action_settings"
          android:showAsAction="never" />
</menu>

The following line is marked with the error given in the title:

android:title="@string/action_search"

although I have added the following line to res/values/strings.xml:

<string name="action_search">SEARCH</string>

I even cleared the project. What is wrong now?

Addendum:

Not sure if this is related, the cause of my problem or caused by my problem: Every variable reference to 'R' has an error: 'R cannot be resolved to a variable'.

Alex
  • 41,580
  • 88
  • 260
  • 469
  • make sure you have insert `action_search` in `string` file in `values` folder, save that file, cleaned your project, – Shayan Pourvatan Jul 17 '14 at 20:14
  • I have - see updated question. – Alex Jul 17 '14 at 20:17
  • try comment that lien ( don't use `action_search` ), then try run your program, did it run? because i think you have a problem in some where else – Shayan Pourvatan Jul 17 '14 at 20:19
  • yes Alex its related, you have an error in one xml file, check menus , layouts , values, manifest file and find problem. syntax problem missing or anything else. – Shayan Pourvatan Jul 17 '14 at 20:20
  • Now the error is gone - I did not do anything!!!! Do I need to wait 1 or 2 minutes until eclipse 'realizes' that an error is resolved? – Alex Jul 17 '14 at 20:20
  • looks like you do not have the correct location for your base package, thus R is not be generated. Show us your manifest file please and then your main activity. – Droid Chris Jul 17 '14 at 20:21
  • No, R will generally give you an error if your XML files have an error. – Shawnic Hedgehog Jul 17 '14 at 20:21
  • It's due to the R.java file not being generated (which is usually due to an error in an xml file): http://stackoverflow.com/questions/4932282/android-r-cannot-be-resolved-to-a-variable – Shadesblade Jul 17 '14 at 20:21
  • I removed the offending line, and all the R-errors vanished. @Saturisk gave the right hint. – Alex Jul 17 '14 at 20:22

1 Answers1

0

I have used AppCompact for implenting the action bar. Below is my menu xml code, please try with the code

<item
    android:id="@+id/action_search"
    android:icon="@drawable/icon_search"
    android:title="@string/search"
    yourapp:actionViewClass="android.support.v7.widget.SearchView"
    yourapp:showAsAction="ifRoom|collapseActionView"/>

    Rest of your xml view...

Devi Indra
  • 23
  • 3