Results 1 to 7 of 7
  1. #1
    pyler is offline Member
    Join Date
    Jul 2012
    Posts
    18
    Rep Power
    0

    Default action_search cannot be resolved or is not a field.

    First of all MyFirstApp runs fine with no errors. Now as That guy from thirdphaseofmoon says, let's get to it.

    I'm currently following this tutorial on adding the action bar to MyFirstApp. I followed the directions exactly. In fact, I copied and pasted the code into MyFirstApp but eclipse throws up this error, "action_search cannot be resolved or is not a field."

    Here's my code:

    Java Code:
    public boolean onOptionsItemSelected(MenuItem item){
    switch(item.getItemId()){
      case R.id.action_search:
      openSearch();
      return true;
    case R.id.action_settings:
      openSettings();
       return true;
    default:
       return super.onOptionsItemSelected(item);
    }
    }
    Additionally, there has been no response to a similar question on StackOverflow

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: action_search cannot be resolved or is not a field.

    Where are the action_... items defined?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    pyler is offline Member
    Join Date
    Jul 2012
    Posts
    18
    Rep Power
    0

    Default Re: action_search cannot be resolved or is not a field.

    action_search is defined in a main_activity_actions.xml file located in the res/menu folder Here's the code
    XML Code:
    <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android" 
          xmlns:yourapp="http://schemas.android.com/apk/res-auto">
        <!-- Search, should appear as action button -->
        <item android:id="@+id/action_search"
              android:icon="@drawable/ic_action_search"
              android:title="@string/action_search"
              yourapp:showAsAction="ifRoom" />
        <!-- Settings, should always be in the overflow -->
        <item android:id="@+id/action_settings"
              android:title="@string/action_settings"
              android:showAsAction="never" />
    </menu>
    Last edited by pyler; 05-16-2014 at 05:35 AM.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: action_search cannot be resolved or is not a field.

    Does the IDE find any errors with that XML file?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    pyler is offline Member
    Join Date
    Jul 2012
    Posts
    18
    Rep Power
    0

    Default Re: action_search cannot be resolved or is not a field.

    No. Eclipse shows no errors or even warnings within the main_activity_actions.xml file.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: action_search cannot be resolved or is not a field.

    I've never used my own namespace. Do you need it or can you use android vs yourapp?
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    pyler is offline Member
    Join Date
    Jul 2012
    Posts
    18
    Rep Power
    0

    Default Re: action_search cannot be resolved or is not a field.

    I didn't know if I was using the support library so I changed the namespace from yourapp to android, but I still get the same error.

Similar Threads

  1. Text Area can not be resolved or is not a field.
    By Zarah in forum New To Java
    Replies: 7
    Last Post: 04-30-2014, 10:25 PM
  2. eclipse java cannot be resolved or is not a field
    By newProgrammer in forum Android
    Replies: 4
    Last Post: 08-31-2012, 05:27 PM
  3. eclipse java cannot be resolved or is not a field
    By newProgrammer in forum Eclipse
    Replies: 1
    Last Post: 08-30-2012, 05:47 PM
  4. cannot be resolved or is not a field
    By Stevemagegod in forum Eclipse
    Replies: 3
    Last Post: 04-10-2012, 12:14 AM
  5. Replies: 4
    Last Post: 01-17-2010, 11:13 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •