Incompatible types error for fragment


#1

Hi I am getting this error in my CrimeActivity.java on the line

fragment = new CrimeFragment();

Incompatible types.
Required:
android.support.v4.app.Fragment
Found:
com.bignerdranch.android.criminalintent.CrimeFragment
?

Could someone explain to me how would I resolve this type of error and what exactly is going on?
Thanks,
Jeff

[code]public class CrimeActivity extends FragmentActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_crime);

    android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragmentContainer);

    if (fragment == null){
        fragment = new CrimeFragment();
        fm.beginTransaction()
                .add(R.id.fragmentContainer, fragment)
                .commit();
    }
}

}[/code]


#2

I am not sure why you have android.support.v4.app.FragmentManager fm = getSupportFragmentManager();.
I have FragmentManager fm = getSupportFragmentManager();


#3

I had the same incompatibility error and this is what worked for me:

import android.support.v4.app.FragmentActivity;

android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
android.support.v4.app.Fragment fragment = fm.findFragmentById(R.id.fragmentContainer);

Although this post is a over a year old, this error may still be a problem with the new versions of Eclipse.