1

I have been trying to add a youtube player to a view flipper by following a tutorial. In said tutorial, the activity that handles the youtube player extends YoutubeBaseActivity. This then gives me errors when i try to use setSupportActionBar. Here are the solutions that i have attempted.

  1. I have tried extending YouTubePlayerFragment, which is what an answer to a similar question on here stated, but the errors are still present.
  2. I also already imported this
import androidx.appcompat.widget.Toolbar;
  1. I have also tried extending AppBarCompact as suggested by some answers, but this then makes the Youtube Player not function and the application crushes.

Does anyone have any suggestions?

This is the tutorial I followed (Skip to 9:45): https://youtu.be/W4hTJybfU7s?t=585

These are the relevant lines of code

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

These are my imports

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;

import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;

import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerSupportFragment;
import com.google.android.youtube.player.YouTubePlayerView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.storage.StorageReference;
import com.squareup.picasso.Picasso;
//import android.support.v7.widget.Toolbar;
import androidx.appcompat.widget.Toolbar;
import java.io.IOException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static android.Manifest.permission.ACCESS_FINE_LOCATION;

My XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimaryDark"
    tools:context=".event_customer_view_activity">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:id="@+id/cust_event_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingTop="30dp"
                android:paddingBottom="10dp"
                android:textColor="@color/LightText"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/cust_event_city"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingTop="20dp"
                android:paddingBottom="20dp"
                android:textColor="@color/LightText"
                android:textSize="15sp" />

            <ViewFlipper
                android:id="@+id/flipperid"
                android:layout_width="match_parent"
                android:layout_height="330dp"
                android:layout_centerInParent="true"
                android:layout_marginTop="20dp"
                android:elevation="5dp"
                android:flipInterval="4000"
                android:inAnimation="@android:anim/slide_in_left"
                android:outAnimation="@android:anim/slide_out_right"></ViewFlipper>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:id="@+id/cust_prev"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_alignParentStart="true"
                    android:layout_marginTop="4dp"
                    android:background="@null"
                    android:src="@drawable/ic_keyboard_arrow_left_black_24dp">

                </ImageView>

                <ImageView
                    android:id="@+id/cust_next"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_alignParentEnd="true"
                    android:layout_marginTop="4dp"
                    android:background="@null"
                    android:src="@drawable/ic_keyboard_arrow_right_black_24dp">

                </ImageView>

                <TextView
                    android:id="@+id/venue_label"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/cust_prev"
                    android:layout_alignParentStart="true"
                    android:paddingTop="20dp"
                    android:paddingBottom="20dp"
                    android:text="Venue: "
                    android:textColor="@color/LightText"
                    android:textSize="20sp" />

                <TextView
                    android:id="@+id/cust_event_venue"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="100dp"
                    android:layout_marginTop="50dp"
                    android:layout_toRightOf="@+id/venue_label"
                    android:paddingTop="20dp"
                    android:paddingBottom="20dp"
                    android:textColor="@color/LightText"
                    android:textSize="20sp" />

                <ImageView
                    android:id="@+id/directions_btn"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_below="@+id/cust_next"
                    android:layout_alignParentEnd="true"
                    android:layout_marginTop="4dp"
                    android:background="@null"

                    android:src="@drawable/ic_directions_black_24dp">

                </ImageView>

                <TextView
                    android:id="@+id/price_label"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/venue_label"
                    android:layout_alignParentStart="true"
                    android:paddingTop="20dp"
                    android:paddingBottom="20dp"
                    android:text="Price: "
                    android:textColor="@color/LightText"
                    android:textSize="20sp" />

                <TextView
                    android:id="@+id/cust_event_price"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/cust_event_venue"
                    android:layout_marginStart="100dp"
                    android:layout_toRightOf="@+id/price_label"
                    android:paddingTop="20dp"
                    android:paddingBottom="20dp"
                    android:textColor="@color/LightText"
                    android:textSize="20sp" />

                <Button
                    android:id="@+id/buy_ticket_btn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/directions_btn"
                    android:layout_alignParentEnd="true"
                    android:layout_marginHorizontal="20dp"
                    android:layout_marginTop="50dp"
                    android:layout_marginBottom="10dp"
                    android:layout_toRightOf="@+id/cust_event_price"
                    android:background="@color/ColorDarkAccent"
                    android:text="Buy Ticket"
                    android:textAllCaps="false"
                    android:textColor="@color/LightText"
                    android:textSize="15sp" />
            </RelativeLayout>

            <TextView
                android:id="@+id/cust_event_desc"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingTop="20dp"
                android:paddingBottom="20dp"
                android:textColor="@color/LightText"
                android:textSize="15sp" />

        </LinearLayout>
    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

And this is the error i am getting:

error: cannot find symbol method setSupportActionBar(Toolbar)

  • Perhaps add a link to said tutorial and add a log of what errors you are getting so we can help you better :) – D.Freeman Jan 28 '20 at 07:54
  • @D.Freeman I have made the necessary edits to include the trouble code, tutorial in question and the logcat info. –  Jan 28 '20 at 08:08
  • Does this answer your question? [setsupportactionbar() throws error](https://stackoverflow.com/questions/28150100/setsupportactionbar-throws-error) – Linda Lawton - DaImTo Jan 28 '20 at 11:58
  • imported package for Toolbar must be import android.support.v7.widget.Toolbar; – VVB Jan 28 '20 at 13:27
  • @VVB I had already done this. The error is still persisting –  Jan 29 '20 at 08:07
  • @DaImTo No it doesn't. The answer you have linked is different from mine since OP isn't attempting to implement a Youtube Player. –  Jan 29 '20 at 08:15
  • Can you post your xml and import section? – VVB Jan 29 '20 at 10:02
  • Alternative is you can try YoutubePlayerSupportFragment. Ref https://stackoverflow.com/questions/35584073/getsupportactionbar-with-youtubebaseactivity – VVB Jan 29 '20 at 10:07
  • @VVB i have edited the question to your liking. Your second suggestion has not worked unfortunately. –  Jan 29 '20 at 13:52

0 Answers0