我试图在Android Studio中简单运行YouTube API v3,并且该应用程序可以正常打开,并带有显示每个功能的按钮列表,但是单击其中的任何一个都会使该应用程序崩溃,并显示以下错误:java.lang.IllegalArgumentException: Developer key cannot be null or empty
。请注意,这不是我的代码,而是来自YouTube的API示例文件夹中的代码。有什么我可以解决的吗?谢谢。
这是“caused by”所显示的 Activity ,它说它在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。
关于android - YouTube API v3示例IllegalArgumentException,Android Studio,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28757094/