Android ActionBarSherlock 给出了大量“调用需要 API 级别 11(当前最小值为 7)”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10260801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:03:03  来源:igfitidea点击:

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

androidactionbarsherlock

提问by vurp0

I downloaded ActionBarSherlock 4.0.3, unzipped it and created a new project from the libraryfolder. The srcfolder 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:

我下载了 ActionBarSherlock 4.0.3,解压并从library文件夹中创建了一个新项目。src根据 Eclipse 的说法,该文件夹充满了错误,因此我按照在线的各种说明进行操作,例如添加android-support-v4.jar、将目标 API 设置为 15 并将编译器合规性级别设置为 1.6。尽管如此,该项目仍有 194 个错误,所有这些错误都是“调用需要 API 级别 11(当前最小值为 7)”。因此,当我查看其中一个错误时,我看到了:

@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.

这对我来说看起来很奇怪,因为invalidateOptionsMenu()它被之前的函数覆盖了,但是 Eclipse 仍然抱怨该函数需要更新的 API 级别。当我查看其他错误时,我发现许多其他错误也是如此。

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.

我对 Python 的经验比 Java 多得多,所以我不明白是什么导致了这种情况的发生。帮助将不胜感激,如果您提供帮助,您能否还解释导致此问题的原因以及您为解决此问题所做的工作?我不想每次遇到问题都问别人,我也想学习。

采纳答案by Joachim Isaksson

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.

由于您使用的是最低 API 级别 7,并且invalidateOptionsMenu()直到 API 级别 11 才存在,因此您无法在没有错误的情况下覆盖它,因为如果设备运行 API 级别 7,则该函数在基类中甚至不可用并且不能覆盖不存在的函数。

回答by Martin Nuc

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

运行 Lint 检查后发生在我身上。尝试右键单击 Sherlock 操作栏项目 -> Android 工具 -> 清除 Lint 标记。

回答by dbrown0708

Use ActivityCompat, provided in the support jar.

使用支持 jar 中提供的ActivityCompat

回答by Mina Fawzy

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

所有这些答案都是错误的,除了 dbrown0708 答案,但我会声明更多

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

您可以使用ActivityCompat在较低的 API 中使用 invalidateOptionMenu正如它在支持库 v4 中提供的那样

Syntax is invalidateOptionsMenu(Activity activity);

语法是 invalidateOptionsMenu(Activity activity);

code is

代码是

ActivityCompat.invalidateOptionsMenu(this);

In API Since level 11

在 API 中 自级别 11

invalidateOptionsMenu();

回答by Chris

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

尝试使用import android.support.v4.app.Fragment; 作为你的图书馆