Jamiil February 2016

I keep getting error with fragment

Thank you guys for your answers. I am now editing the question after considering all your solutions guys but I am still getting error. I am using support v4 now.

Here is the result. I keep getting the same error in the switch case block of code enter image description here]

These are my current imports import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager;

Here a new error I am getting after I changed the imports again guys enter image description here

Answers


Illya Bublyk February 2016

Remove all Fragment's import from class and import android.support.v4.app.Fragment again


Avinash Joshi February 2016

the problem is the fragment that you are using is a of type android.support.v4.app.Fragment and the method requires the fragment of type android.app.Fragment so you can go to your fragment remove the import statement of Fragment import android.support.v4.app.Fragment and add import android.app.Fragment it should work

the activity you are using the fragment in must extend the FragmentActivity and in place of getFragmentManger you should use getSuppotFragmentManager

public class YourActivity extends FragmentActivity{

}

and the fragments also must be of type android.support.v4.app.Fragment


Aziz February 2016

There are two ways we can use fragments

  1. By importing fragment manager and fragments from support v4 library to support lower OS versions devices.

  2. By importing it from standard android API

Here you are trying to use fragment from 1 and FragmentManager from other.

Hence you should use both from anyone I would suggest you to use support v4 library


Jamiil February 2016

Hey guys the problem is solved. I forgot to change the imports in the fragments to import android.support.v4.app.Fragment;. I only changed the imports in the main activity. That was so stupid of me that I could not recognize such a simple mistake. Thank you for your help :)

Post Status

Asked in February 2016
Viewed 2,500 times
Voted 4
Answered 4 times

Search




Leave an answer