0
11-26 15:50:58.159: E/AndroidRuntime(3199): java.lang.NoClassDefFoundError: com.android.PlayMedia
11-26 15:50:58.159: E/AndroidRuntime(3199): at com.android.Description.onClick(Description.java:63)
行號63java.lang.NoClassDefFoundError:同時使用YouTube API
startActivity(new Intent(Description.this,PlayMedia.class));
PlayMedia.java
public class PlayMedia extends YouTubeFailureRecoveryActivity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.play_media);
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);
}
}
YouTubeFailureRecoveryActivity.java
(由YouTube本身提供)public abstract class YouTubeFailureRecoveryActivity extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener {
private static final int RECOVERY_DIALOG_REQUEST = 1;
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
YouTubeInitializationResult errorReason) {
if (errorReason.isUserRecoverableError()) {
errorReason.getErrorDialog(this, RECOVERY_DIALOG_REQUEST).show();
} else {
String errorMessage = String.format(getString(R.string.error_player), errorReason.toString());
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RECOVERY_DIALOG_REQUEST) {
// Retry initialization if user performed a recovery action
getYouTubePlayerProvider().initialize(DeveloperKey.DEVELOPER_KEY, this);
}
}
protected abstract YouTubePlayer.Provider getYouTubePlayerProvider();
}
我已在我的Manifest
文件中註冊了活動PlayMedia
。
我已經試過了,它沒有幫助 – onkar
您是否使用任何外部罐子? –
是的,重新啓動了日食並重試了這些步驟,結果奏效了。 – onkar