问题
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.
回答1:
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.
回答2:
Happened to me after running Lint checks. Try right click on sherlock action bar project -> Android tools -> Clear Lint Markers.
回答3:
Use ActivityCompat, provided in the support jar.
回答4:
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();
回答5:
Try and use the import android.support.v4.app.Fragment; as your library
来源:https://stackoverflow.com/questions/10260801/actionbarsherlock-gives-tons-of-call-requires-api-level-11-current-min-is-7