0

我创建了一个示例代码来查看 youtube 活动。

Here's the code,
package com.example.newandroid;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayerView;
public class VideoActivity extends  YouTubeBaseActivity implements     
     YouTubePlayer.OnInitializedListener{
String urlVideo;
public void onCreate(Bundle savedInstance){

    super.onCreate(savedInstance);
    setContentView(R.layout.main);

      urlVideo="5lbVNYAeFiQ";

      YouTubePlayerView youTubeView = (YouTubePlayerView) 
                              findViewById(R.id.youtube_api_demo);

        youTubeView.initialize("MY_API_KEY", this);
}
   @Override
   public void onInitializationFailure(Provider arg0,
    YouTubeInitializationResult arg1) {
    // TODO Auto-generated method stub
   Toast.makeText(this, "Error ", Toast.LENGTH_LONG).show(); 
    }

   @Override
    public void onInitializationSuccess(Provider arg0, YouTubePlayer arg1,
    boolean arg2) {
// TODO Auto-generated method stub
Toast.makeText(this, "Success ", Toast.LENGTH_LONG).show(); 

      }
        }

我创建了 main.xml,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
  android:layout_height="match_parent"
    android:orientation="vertical" >
 <youtube_api_demo 
 android:name="com.google.android.youtube.player.YouTubePlayer"
    android:id="@+id/youtube_api_demo"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
</LinearLayout>

我的 manifest.xml 是

  <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.newandroid"
  android:versionCode="1"
  android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />
  <uses-permission android:name="android.permission.INTERNET"/>


 <application  android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

  <activity
    android:label="@string/youtube_api_demo"
    android:name="com.example.newandroid.VideoActivity">
  <intent-filter >
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
  <meta-data android:name="@string/isLaunchableActivity" android:value="false"/>
   </activity>
  </application></manifest>.

这段代码有什么问题。我收到以下错误,android.view.InflateException: Binary XML file line #6: Error inflating class

4

1 回答 1

1

它,大概,应该是

<com.google.android.youtube.player.YouTubePlayerView
   android:id="@+id/youtube_api_demo"
.....
/>
于 2013-04-08T07:29:59.510 回答