18

I downloaded ActionBarSherlock 4.0.3, unzipped it and created a new project from the library folder. The src folder was, according to Eclipse, full of errors, so I followed various instructions online, like adding android-support-v4.jar, setting target API to 15 and compiler compliance level to 1.6. Still, the project has 194 errors, all of which are "Call requires API level 11 (current min is 7)". So when I look at one of the errors, I see this:

@Override
public void invalidateOptionsMenu() {
    getSherlock().dispatchInvalidateOptionsMenu();
}

public void supportInvalidateOptionsMenu() {
    invalidateOptionsMenu();
    //the previous line has this error in Eclipse:
    //Call requires API level 11 (current min is 7): android.app.Activity#invalidateOptionsMenu
}

This looks strange to me, because invalidateOptionsMenu() is overridden with the previous function, but Eclipse still complains about the function requiring a newer API level. When I look at the other errors, I find that this is the case with many other errors too.

I have much more experience with Python than Java, so I don't understand anything of what causes this to happen. Help would be appreciated, and if you do help, could you also explain what causes this and what you did to solve it? I wouldn't want to ask someone every time I have a problem, I want to learn too.

vurp0
  • 1,035
  • 2
  • 9
  • 13
  • Seems Eclipse for some reason does not agree that you set the API level to 15. Did you double check that your change "stuck" and didn't change back to 7? – Joachim Isaksson Apr 21 '12 at 16:25
  • I'm not exactly sure what you mean. I have min API level set to 7, and target API level set to 15. I was wondering why it thought the function requires a higher API, when clearly the function (that would normally require >11) is previously overridden. – vurp0 Apr 21 '12 at 16:41

5 Answers5

37

Happened to me after running Lint checks. Try right click on sherlock action bar project -> Android tools -> Clear Lint Markers.

Martin Nuc
  • 5,604
  • 2
  • 42
  • 48
  • 2
    This answer is just a temporary fix. It doesn't make the problem go away, it just makes Eclipse forget there was a problem. :/ – AlbeyAmakiir Mar 06 '14 at 00:20
  • If you rerun Lint checks they will pass after clearing. It doesn't make Eclipse to forget there is a problem. The original question had nothing to do with my code at all. I've just found this question during my search. – Martin Nuc Nov 01 '14 at 22:43
20

Use ActivityCompat, provided in the support jar.

dbrown0708
  • 4,544
  • 4
  • 25
  • 22
7

Since you're using min API level 7, and invalidateOptionsMenu() did not exist until API level 11, you can't override it without errors since if the device runs API level 7, the function isn't even available in the base class and a non existing function cannot be overridden.

Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
  • 1
    So I set the min API level on `com_actionbarsherlock` to 11, and what do you know, it worked! Thank you! – vurp0 Apr 21 '12 at 17:06
  • 17
    ABS provides this method. Eclipse is wrong/ADT isn't smart enough – Jake Wharton Apr 22 '12 at 03:43
  • @Jake Do you have other suggestions? I got further problems with ClassNotFoundException afterwards in my project, but I thought that was unrelated. Could it be this? I can create another question. – vurp0 Apr 22 '12 at 19:19
  • Yes it is likely unreleated. The minimum SDK for ABS is 7 and these messages are just warnings, not errors. – Jake Wharton Apr 23 '12 at 17:42
  • 75
    You can use `supportInvalidateOptionsMenu()` – Oleg Vaskevich Jun 04 '12 at 06:19
  • Yes just use supportInvalidateOptionsMenu() – tasomaniac Feb 19 '13 at 14:19
  • Same problem just caught me in styles.xml - annoying. There, lint claims that `showHome|useLogo` is only available from SDK 11 on... *sigh* Nice if it works, annoying the way it is... – Zordid Aug 27 '13 at 19:37
  • You do not have to increase your API level, just use **supportInvalidateOptionsMenu();** if you are in an activity and if you are in a fragment use **getActivity().supportInvalidateOptionsMenu();** – Kaveesh Kanwal Jun 24 '15 at 06:18
1

All this answers are wrong Except dbrown0708 Answer but I will declare it more

You Can use invalidateOptionMenu in lower API by using ActivityCompat As it provided in support library v4

Syntax is invalidateOptionsMenu(Activity activity);

code is

ActivityCompat.invalidateOptionsMenu(this);

In API Since level 11

invalidateOptionsMenu();
Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156
0

Try and use the import android.support.v4.app.Fragment; as your library

Chris
  • 4,593
  • 1
  • 33
  • 37