Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionBarSherlock gives tons of "Call requires API level 11 (current min is 7)" errors

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.

like image 204
vurp0 Avatar asked Apr 21 '12 16:04

vurp0


4 Answers

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

like image 145
Martin Nuc Avatar answered Oct 23 '22 17:10

Martin Nuc


Use ActivityCompat, provided in the support jar.

like image 31
dbrown0708 Avatar answered Oct 23 '22 15:10

dbrown0708


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.

like image 7
Joachim Isaksson Avatar answered Oct 23 '22 16:10

Joachim Isaksson


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();
like image 1
Mina Fawzy Avatar answered Oct 23 '22 17:10

Mina Fawzy