title: Using Youtube API in android?
body: <pre><code>public class MainActivity extends YouTubeBaseActivity {
  
  Button b;
  private YouTubePlayerView youTubePlayerView;
  private YouTubePlayer.OnInitializedListener onInitializedListener;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      youTubePlayerView = (YouTubePlayerView) findViewById(R.id.view4);
      onInitializedListener = new YouTubePlayer.OnInitializedListener() {
          @Override
          public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
              youTubePlayer.loadVideo("KRavtGE-qsI");
  
          }
  
          @Override
          public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
  
          }
      };
  
      b= (Button) findViewById(R.id.button4);
      b.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              youTubePlayerView.initialize("my key",onInitializedListener);
          }
      });
  
  }
  }
  </code></pre>
  
  <p>XML FILE</p>
  
  <pre><code>&lt;RelativeLayout
      android:layout_width="368dp"
      android:layout_height="495dp"
      tools:layout_editor_absoluteX="8dp"
      tools:layout_editor_absoluteY="8dp"&gt;
  
      &lt;Button
          android:id="@+id/button4"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_centerHorizontal="true"
          android:layout_marginBottom="173dp"
          android:text="Button" /&gt;
  
      &lt;com.google.android.youtube.player.YouTubePlayerView
          id="@+id/view4"
          layout_above="@+id/button4"
          layout_marginBottom="109dp"
          layout_marginLeft="54dp"
          layout_marginStart="54dp"
          layout_toEndOf="@+id/button4"
          layout_toRightOf="@+id/button4"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" /&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>When I click on the button of the app then It unfortunately stops. Can anyone please help me on this project? I build this project new version of android studio.I dint know why this happened.. cay any please help me in solve my problem.. </p>