错误:MenuItemCompat:getActionProvider项目未实现SupportMenuItem返回null

时间:2015-12-11 08:43:41

标签: android titanium

您好我正在为Chromecast上的视频投射开发Titanium Android模块。我正在以编程方式创建菜单。我正在使用下面的代码:

菜单代码

protected Menu newMenuInstance(Context context) {
    try 
    {
        Class<?> menuBuilderClass = Class.forName("com.android.internal.view.menu.MenuBuilder");
        Constructor<?> constructor = menuBuilderClass.getDeclaredConstructor(Context.class);

        return (Menu) constructor.newInstance(context);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
} 

投射按钮代码:

@Kroll.method
public void castButtonLoader(){

    Menu menu= newMenuInstance(TiApplication.getInstance());

    int menuId= TiApplication.getAppRootOrCurrentActivity().getResources().getIdentifier("main", "menu",TiApplication.getInstance().getPackageName());
    new MenuInflater(getActivity().getApplicationContext()).inflate(menuId, menu);

    MenuItem mediaRouteMenuItem;    
    mediaRouteMenuItem = menu.findItem(menuId);

    MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider) MenuItemCompat.getActionProvider(mediaRouteMenuItem);
    // Set the MediaRouteActionProvider selector for device discovery.
    mediaRouteActionProvider.setRouteSelector(mMediaRouteSelector);
}

返回给定错误:

  

MenuItemCompat:getActionProvider:item未实现SupportMenuItem;返回null

有人可以帮忙解决为什么会出现此错误吗?

1 个答案:

答案 0 :(得分:0)

我们正在使用AppCompat库,因此看起来这个错误告诉您这只会接受来自AppCompat的菜单项:

android.support.v7.internal.view.menu.MenuBuilder