gpt4 book ai didi

java - YouTube Player崩溃(java.lang.NullPointerException,空对象引用)

转载 作者:行者123 更新时间:2023-12-03 06:15:39 24 4
gpt4 key购买 nike

我的YouTube播放器崩溃了,我不知道为什么。

这是我的Java代码:
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_youtube);
工具栏工具栏=(工具栏)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);


playerFragment = (YouTubePlayerSupportFragment) getSupportFragmentManager().findFragmentById(R.id.youtube_player_fragment);
playerFragment.initialize(YouTubeKey, this);
}



@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
mPlayer = youTubePlayer;

//Enables automatic control of orientation
mPlayer.setFullscreenControlFlags(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION);

//Show full screen in landscape mode always
mPlayer.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE);

//System controls will appear automatically
mPlayer.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI);

if (!b) {
mPlayer.cueVideo("xxx");
mPlayer.loadVideo("xxx");
}
else
{
mPlayer.play();
}
}

@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
mPlayer = null;
String ausgabe = youTubeInitializationResult.toString();
Log.d("hi", ausgabe);
} }

问题解决了

最佳答案

现在,我们需要一些其他信息来明确地回答这个问题,但是看来该行返回的是null,这表明您希望查看资源XML并确保正确抓取了该片段。
getSupportFragmentManager().findFragmentById(R.id.youtube_player_fragment);
您可能会受益于以下相关问题:

findFragmentById return null

我怀疑问题可能出在您的资源XML中,您没有使用支持库声明该片段。

尝试使用:

<fragment
android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"

关于java - YouTube Player崩溃(java.lang.NullPointerException,空对象引用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44269417/

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