我用youtube视图和东西制作一个简单的应用程序,但每当我运行应用程序时,我没有错误,但应用程序没有打开,在我的模拟器上它说“CFBC(我的应用程序的名称)已停止运行”这里是我的代码我有6个活动,我知道它很多,但如果有人能告诉我为什么它崩溃0错误将有助于一吨
package org.cfbcla.cfbc;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
import java.util.ArrayList;
import java.util.List;
/**
* Created by kwia on 8/4/17.
*/
public class Display extends AppCompatActivity {
YouTubePlayerView mYouTubePlayerView;
Button btnPlay;
YouTubePlayer.OnInitializedListener mOnInitializedListener;
@Override
public void onBackPressed() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display);
btnPlay = (Button) findViewById(R.id.btnPlay);
mYouTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtubePlay);
mOnInitializedListener = new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
List<String> videoList = new ArrayList<>();
videoList.add("QOwE0XQei_M");
videoList.add("5sTXWESDBB0");
youTubePlayer.loadVideos(videoList);
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
};
btnPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mYouTubePlayerView.initialize(YTConfig.getApiKey(), mOnInitializedListener);
}
});
}
public void onButtonclick4(View v4) {
if (v4.getId() == R.id.button3) {
Intent i4 = new Intent(Display.this, MainActivity.class);
startActivity(i4);
}
}
}
package org.cfbcla.cfbc;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
/**
* Created by kwia on 8/4/17.
*/
public class Display2 extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display2);
}
public void onButtonclick4(View v4) {
if (v4.getId() == R.id.button) {
Intent i4 = new Intent(Display2.this, MainActivity.class);
startActivity(i4);
}
}
}
package org.cfbcla.cfbc;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
/**
* Created by kwia on 8/4/17.
*/
public class Display3 extends AppCompatActivity{
YouTubePlayerView mYouTubePlayerView;
Button btnPlay;
YouTubePlayer.OnInitializedListener mOnInitializedListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display3);
btnPlay = (Button) findViewById(R.id.btnPlay);
mYouTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtubePlay);
mOnInitializedListener = new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.loadVideo("sFXQ1vAaKXA");
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
};
btnPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mYouTubePlayerView.initialize(YTConfig.getApiKey(), mOnInitializedListener);
}
});
}
public void onButtonclick4(View v4) {
if (v4.getId() == R.id.button) {
Intent i4 = new Intent(Display3.this, MainActivity.class);
startActivity(i4);
}
}
}
package org.cfbcla.cfbc;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
/**
* Created by kwia on 8/4/17.
*/
public class Display4 extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display4);
}
public void onButtonclick4(View v4) {
if (v4.getId() == R.id.button4) {
Intent i4 = new Intent(Display4.this, MainActivity.class);
startActivity(i4);
}
}
}
package org.cfbcla.cfbc;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onButtonClick(View v) {
if (v.getId() == R.id.A) {
Intent i = new Intent(MainActivity.this, Display.class);
startActivity(i);
}
}
public void onButtonClick2(View v2) {
if (v2.getId() == R.id.C) {
Intent i2 = new Intent(MainActivity.this, Display2.class);
startActivity(i2);
}
}
public void onbuttonClick3(View v3) {
if (v3.getId() == R.id.S) {
Intent i3 = new Intent(MainActivity.this, Display3.class);
startActivity(i3);
}
}
public void onButtonclick4(View v4) {
if (v4.getId() == R.id.M) {
Intent i4 = new Intent(MainActivity.this, Display4.class);
startActivity(i4);
}
}
}