YouTube API v3示例非法辩论异常,安卓工作室



我试图在Android Studio中简单地运行YouTube API v3,应用程序打开时会显示一系列显示每个功能的按钮,但点击其中任何一个按钮都会导致应用程序崩溃,并出现以下错误:java.lang.IllegalArgumentException: Developer key cannot be null or empty。请注意,这不是我的代码,而是来自YouTube的API示例文件夹中的代码。我能做些什么来解决这个问题吗?谢谢

这是"由"显示的活动,它说它在DEVELOPER_KEY行。

/*
 * Copyright 2012 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.examples.youtubeapidemo;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
import android.os.Bundle;
/**
 * A simple YouTube Android API demo application which shows how to create a simple application that
 * displays a YouTube Video in a {@link YouTubePlayerView}.
 * <p>
 * Note, to use a {@link YouTubePlayerView}, your activity must extend {@link YouTubeBaseActivity}.
 */
public class PlayerViewDemoActivity extends YouTubeFailureRecoveryActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.playerview_demo);
    YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
    youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);
  }
  @Override
  public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
      boolean wasRestored) {
    if (!wasRestored) {
      player.cueVideo("wKJ9KzGQq0w");
    }
  }
  @Override
  protected YouTubePlayer.Provider getYouTubePlayerProvider() {
    return (YouTubePlayerView) findViewById(R.id.youtube_view);
  }
}

LOGCAT

 FATAL EXCEPTION: main
    Process: com.examples.youtubeapidemo, PID: 10226
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.examples.youtubeapidemo/com.examples.youtubeapidemo.PlayerViewDemoActivity}: java.lang.IllegalArgumentException: Developer key cannot be null or empty
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2523)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2582)
            at android.app.ActivityThread.access$900(ActivityThread.java:174)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5731)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.IllegalArgumentException: Developer key cannot be null or empty
            at com.google.android.youtube.player.internal.ab.a(Unknown Source)
            at com.google.android.youtube.player.YouTubePlayerView.initialize(Unknown Source)
            at com.examples.youtubeapidemo.PlayerViewDemoActivity.onCreate(PlayerViewDemoActivity.java:39)
            at android.app.Activity.performCreate(Activity.java:5580)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2487)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2582)
            at android.app.ActivityThread.access$900(ActivityThread.java:174)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5731)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)

您需要按照YouTube Api的步骤操作。检查步骤4。

最新更新