Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

291
Vistas
This cast can never be succeed. Androidx

I'm using androidx fragment but get always null reference of youTubeFragment and it's because of different casting.image

import androidx.fragment.app.Fragment

val youtubeFragment = 
childFragmentManager.findFragmentById(R.id.playbackYoutubeFragment) as 
com.google.android.youtube.player.YouTubePlayerFragment

youtube fragment import is:

import android.app.Fragment;

my layout:

<fragment
android:id="@+id/playbackYoutubeFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" 
android:name="com.google.android.youtube.player.
YouTubePlayerFragment"
app:layout_constraintTop_toTopOf="parent"/>

Is there any solution to solve that problem? or i have to change my fragment type.Actually i don't want to change my androidx fragment type. help is always appreciated.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

It's because your childFragmentManager is from AndroidX package, therefore findFragmentById's return type is androidx.Fragment. YouTubePlayerSupportFragment is android.support.v4.app.Fragment so in compile-time, these are two separate types that cannot be cast to each other.

The problem is Youtube SDK not using androidx. You can fix this by enabling jetifier, add following code to your gradle.properties:

android.enableJetifier=true

This will fix the problem by migrating all support classes in third party libraries to androidx, so your cast will succeed in runtime. However, Android studio warning will still be present - you can suppress it:

// CAST_NEVER_SUCCEEDS can be ignored - happens because Youtube SDK's fragment is not
// androidx.Fragment, but Jetifier will take care of that and cast will succeed
@Suppress("CAST_NEVER_SUCCEEDS")
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda