Hello! Studying android on the book HeadFirst There was a problem
This is onCreate MainActivity
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WorkoutDetailFragment fragment = (WorkoutDetailFragment) getFragmentManager().findFragmentById(R.id.detail_frag); fragment.setWorkout(1); } This is the xml fragment:
<fragment class="workout.hfad.com.workout.WorkoutDetailFragment" android:id="@+id/detail_frag" android:layout_width="0dp" android:layout_weight="3" android:layout_height="match_parent" /> Swears at the line
<WorkoutDetailFragment fragment = (WorkoutDetailFragment) getFragmentManager().findFragmentById(R.id.detail_frag); And it gives an error:
`Inconvertible types; cannot cast 'android.app.Fragment' to 'workout.hfad.com.workout.WorkoutDetailFragment' Actually, I did everything according to the book (sort of). Where is the mistake?
WorkoutDetailFragmentdoes not expandFragment- YuriySPb ♦android.app.Fragmentorandroid.support.v4.app.Fragment? If you use from support, then theActivityshould be from the same place andgetSupportFragmentManager()should be used. - woesss