Nikhil Soni Nikhil Soni - 3 months ago 10x
Java Question

Issue with fragment transaction

package com.androidnik.tourguide;

import android.os.Bundle;

public class MustVisit extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {
getSupportFragmentManager().beginTransaction().replace(, new MustVisitFragment()).commit();

im getting this error : Error:(12, 80) error: incompatible types: MustVisitFragment cannot be converted to Fragment
i have extended that fragment class within MyVisitFragment class and also have a empty constructor still im facing this problem


The problem you're facing is with incompatibility between and support.v4.Fragment. These two are not the same, and each has it's own FragmentManager they work with.

You are using getSupportFragmentManager which means your fragment should extend support.v4.Fragment (check the imports, and change to this). Either change that or get the other fragment manager by calling getFragmentManager.

I'd personally suggest working with the support library, since in one of my projects, it proved good to me, while I had various problems with the other one, but this is purely my opinion.