gpt4 book ai didi

android - 添加媒体路由器转换按钮时出错

转载 作者:太空宇宙 更新时间:2023-11-03 10:19:40 25 4
gpt4 key购买 nike

我尝试使用 CastCompanionLibrary 为我的应用程序实现一个转换函数.当它尝试将 Media Router Cast Button 添加到 ActionBar 时,出现此错误:

10-03 19:33:20.098  11781-11781/de.resper.e2cast W/MenuItemCompat﹕ getActionProvider: item does not implement SupportMenuItem; returning null
10-03 19:33:20.098 11781-11781/de.resper.e2cast W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41ebde18)
10-03 19:33:20.098 11781-11781/de.resper.e2cast E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: de.resper.e2cast, PID: 11781
java.lang.NullPointerException
at com.google.sample.castcompanionlibrary.cast.BaseCastManager.addMediaRouterButton(BaseCastManager.java:355)
at de.resper.e2cast.ChannelCastActivity.onCreateOptionsMenu(ChannelCastActivity.java:655)

在CahnnelCastActivity中的位置是:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.main, menu);
mCastManager.addMediaRouterButton(menu, R.id.media_route_menu_item); <--- ERROR
return true;
}

我已经包括:

import android.support.v7.app.ActionBarActivity;

并扩展为:

public class ChannelCastActivity extends ActionBarActivity

在 BaseCastManager 中是错误行:

public MenuItem addMediaRouterButton(Menu menu, int menuResourceId) {
MenuItem mediaRouteMenuItem = menu.findItem(menuResourceId);
MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider) MenuItemCompat.getActionProvider(mediaRouteMenuItem);
mediaRouteActionProvider.setRouteSelector(mMediaRouteSelector); <--- ERROR
if (null != getMediaRouteDialogFactory()) {
mediaRouteActionProvider.setDialogFactory(getMediaRouteDialogFactory());
}
return mediaRouteMenuItem;
}

在 AndroidManifest.xml 中:

    <activity
android:name=".ChannelCastActivity"
android:label="@string/title_activity_channel_cast"
android:theme="@style/Theme.AppCompat.Light"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="de.resper.e2cast.MainActivity" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</activity>

最佳答案

确保您的菜单项具有 android.support.v7.app.MediaRouteActionProvider 的操作 View 而不是 android.app.MediaRouteActionProvider - Chromecast 需要 support-v7 版本。

关于android - 添加媒体路由器转换按钮时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26184306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com