在运行时在android中膨胀类片段时出错

时间:2016-10-02 13:51:47

标签: java android android-fragments

这是我的youtube布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <fragment
        android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
        android:id="@+id/youtube_fragment"
        android:layout_width="match_parent"
        android:layout_height="450dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />


    <ProgressBar
        android:id="@+id/progressbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:visibility="gone" />

    <ImageView
        android:id="@+id/novideo"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/player"
        android:visibility="gone"
        android:scaleType="fitXY"/>

</RelativeLayout>

这是youtube播放器的Fragment代码。

public class FragmentVideo extends Fragment {

    String url = "http://techslides.com/demos/sample-videos/small.3gp";

    ProgressBar progressBar;
    Category category;
    Context context;
    MediaController mediaController;
    private FragmentActivity myContext;

    private YouTubePlayer YPlayer;
    private static final String YoutubeDeveloperKey = "xyz";
    private static final int RECOVERY_DIALOG_REQUEST = 1;

    ImageView novideo;

    public FragmentVideo() {
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_video, container, false);

        final VideoView videoView = (VideoView) view.findViewById(R.id.video);
        progressBar = (ProgressBar) view.findViewById(R.id.progressbar);
        novideo = (ImageView) view.findViewById(R.id.novideo);
        context = getActivity();
        SharedPreferences pref = context.getApplicationContext().getSharedPreferences("MyPref", 0);

        final String video = pref.getString("video", "");

        View rootView = inflater.inflate(R.layout.fragment_video, container, false);

        YouTubePlayerSupportFragment youTubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
        FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
        transaction.add(R.id.youtube_fragment, youTubePlayerFragment).commit();

        youTubePlayerFragment.initialize("DEVELOPER_KEY", new OnInitializedListener() {

            @Override
            public void onInitializationSuccess(Provider arg0, YouTubePlayer youTubePlayer, boolean b) {
                if (!b) {
                    YPlayer = youTubePlayer;
                    YPlayer.setFullscreen(true);
                    YPlayer.loadVideo("2zNSgSzhBfM");
                    YPlayer.play();
                }
            }

            @Override
            public void onInitializationFailure(Provider arg0, YouTubeInitializationResult arg1) {}
        });

        return  null;
    }
}

我在编译时遇到错误。

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mani.advertise/com.mani.activity.DetailActivity}: android.view.InflateException: Binary XML file line #93: Binary XML file line #13: Binary XML file line #13: Error inflating class

0 个答案:

没有答案