Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

289
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!