我想在我的应用程序中使用YoutubePlayerSupportFragment
来播放YouTube视频,但它会出现以下异常:
01-08 14:52:11.953: E/AndroidRuntime(4069): FATAL EXCEPTION: main
01-08 14:52:11.953: E/AndroidRuntime(4069): java.lang.NullPointerException
01-08 14:52:11.953: E/AndroidRuntime(4069): at com.google.android.youtube.player.YouTubePlayerSupportFragment.onStart(Unknown Source)
01-08 14:52:11.953: E/AndroidRuntime(4069): at android.support.v4.app.Fragment.performStart(Fragment.java:1524)
01-08 14:52:11.953: E/AndroidRuntime(4069): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:957)
01-08 14:52:11.953: E/AndroidRuntime(4069): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
我使用以下逻辑替换我的片段:
Fragment fragment=new EditBloop();
final FragmentTransaction ft1 = getFragmentManager().beginTransaction();
ft1.replace(R.id.container, fragment, "edit");
ft1.commit();
My Fragment类如下:
public class EditBloop extends YouTubePlayerSupportFragment
{
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.edit_bloop, null);
}
和我的xml edit_bloop:
<fragment
android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
android:id="@+id/youtubeplayerview"
android:layout_width="match_parent"
android:layout_height="200dp"/>
那么,请指导我如何解决这个问题?
答案 0 :(得分:0)
尝试使用getSupportFragmentManager()
,如下所示:
EditBloop fragment = EditBloop.newInstance("edit");
getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment).commit();