Youtube Android API - 调用AppVersion不能为null或为空

时间:2013-07-09 13:38:58

标签: java android youtube-api android-youtube-api

因此,在我的片段中,我将以下代码用于处理listview的onclickitem

ls.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    ChannelItem c = (ChannelItem) parent.getAdapter().getItem(position);
                    Intent myIntent = new Intent(getActivity().getBaseContext(), PlayerViewActivity.class);
                    myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    getActivity().getBaseContext().startActivity(myIntent);
                }
            });

我知道这不是最干净的代码,我打算重新格式化。但它暂时有效(我在使用YoutubeBaseActivity之前使用测试活动对其进行了测试)。只是为了澄清这段代码没有问题,但它是为了说明我正在遵循的流程。

因此,当youtube活动开始时,它将执行以下类

public class PlayerViewActivity extends YouTubeBaseActivity implements
        YouTubePlayer.OnInitializedListener {

    static private final String VIDEO = "4SK0cUNMnMM";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.youtube_player);
        YouTubePlayerView youTubeView = (YouTubePlayerView)
                findViewById(R.id.youtube_view);
        youTubeView.initialize(Api.DEV_KEY, this);
    }
    @Override
    public void onInitializationFailure(YouTubePlayer.Provider provider,
                                        YouTubeInitializationResult error) {
        Toast.makeText(this, "Oh no! "+error.toString(),
                Toast.LENGTH_LONG).show();
    }
    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
                                        boolean wasRestored) {
        player.loadVideo(VIDEO);
    }

}

这是我无处可寻的任何帮助

youTubeView.initialize(Api.DEV_KEY, this);

这行代码一遍又一遍地抛出相同的错误

  Caused by: java.lang.IllegalArgumentException: callingAppVersion cannot be null or empty
            at com.google.android.youtube.player.internal.ac.a(Unknown Source)
            at com.google.android.youtube.player.internal.o.<init>(Unknown Source)
            at com.google.android.youtube.player.internal.ad.a(Unknown Source)
            at com.google.android.youtube.player.YouTubePlayerView.a(Unknown Source)
            at com.google.android.youtube.player.YouTubeBaseActivity$a.a(Unknown Source)
            at com.google.android.youtube.player.YouTubePlayerView.initialize(Unknown Source)
            at view.PlayerViewActivity.onCreate(PlayerViewActivity.java:44)
            at android.app.Activity.performCreate(Activity.java:5104)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
            ... 11 more

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:6)

您需要将应用程序的版本代码和版本名称添加到清单文件中,例如:

android:versionCode="1"
android:versionName="1.0"