Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

295
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda