Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ActionBarSherlock:getSupportMenuInflator()未定义_Android_Actionbarsherlock - Fatal编程技术网

Android ActionBarSherlock:getSupportMenuInflator()未定义

Android ActionBarSherlock:getSupportMenuInflator()未定义,android,actionbarsherlock,Android,Actionbarsherlock,我正在使用ActionBarSherlock并试图通过使用getSupportMenuInflator()膨胀我的XML菜单,但它给出了一个错误: the method getSupportMenuInflator() is undefined for the type ... 我不明白它为什么会显示错误。代码如下: public void onCreateOptionsMenu(Menu menu) { getSupportMenuInflater().inflate(R.menu.

我正在使用ActionBarSherlock并试图通过使用
getSupportMenuInflator()
膨胀我的XML菜单,但它给出了一个错误:

the method getSupportMenuInflator() is undefined for the type ...
我不明白它为什么会显示错误。代码如下:

public void onCreateOptionsMenu(Menu menu) {
    getSupportMenuInflater().inflate(R.menu.activity_main, menu);
    ...
}
如何修复它?

您需要使用:

getSherlockActivity().getSupportMenuInflater().inflate(R.menu.activity_main, menu);

因为
getSupportMenuInflater()
是SherlockActivity中的一个方法,而不是SherlockFragment。

如果您使用的是SherlockActionBar,您应该
实现SherlockActivity
,而不是
Activity和getSupportMenuInflater()
将可用

项目中是否包含ABS库?是的,这是我做的第一件事。好的。知道了。但是现在它给出了一个错误:类型MenuInflater中的方法inflate(int,Menu)不适用于参数(int,Menu)??您需要导入ABS菜单和MenuItem类:
import com.actionbarsherlock.view.Menu
导入com.actionbarsherlock.view.MenuItem不是Android版本。