1
package com.androidnik.tourguide;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MustVisit extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_category);
    getSupportFragmentManager().beginTransaction().replace(R.id.container, 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

Vucko
  • 7,371
  • 2
  • 27
  • 45
Nikhil Soni
  • 119
  • 9
  • 1
    Possible duplicate of [incompatible types: HomeFragment cannot be converted to Fragment in Android](http://stackoverflow.com/questions/27037662/incompatible-types-homefragment-cannot-be-converted-to-fragment-in-android) – Harshad Pansuriya Jul 09 '16 at 10:17
  • Did you manage to fix it ? – Vucko Jul 09 '16 at 14:33

3 Answers3

1

The problem you're facing is with incompatibility between android.app.Fragment 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.

Vucko
  • 7,371
  • 2
  • 27
  • 45
  • i have used the v4 import but i dont think its using the import as the v4 import is grayed out and alos i have set my min sdk to 23 – Nikhil Soni Jul 09 '16 at 15:17
  • 1
    That does not matter. Remove the `android.app.Fragment` import and leave only the `support.v4.Fragment`. Do this in your `MustVisitFragment` – Vucko Jul 09 '16 at 15:22
0

Replace android.R.id.content with R.id.container

0

Add imports:

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

Will solve your issue.

Ravi Rawal
  • 233
  • 3
  • 14