Fragment isn't able to be cast

In my activity file, I have

FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentById(R.id.fragmentContainer);

if (fragment == null){
    fragment = new CrimeFragment();
}

The class CrimeFragment is in another java file, called CrimeFragment.java, where it's defined as

public class CrimeFragment extends Fragment {

    private Crime mCrime;
    private EditText mTitlefield;

}

I get an error in Android Studio saying that fragment needs a Fragment object but is being given a CrimeFragment object. Shouldn't this be no problem though since CrimeFragment extends Fragment?

Answers


Most likely you're importing different Fragment objects, the normal one, and the android.support.v4.app.Fragment one.


Need Your Help

byte array to pdf file with asp.net

asp.net pdf byte

I have a byte array and now I want to convert the byte array to a pdf file. I am using the following code, but when I try to see/open the pdf file, it shows

how to append date in log file name , like log_12.12.2012.log?

java xml logging log4j rollingfileappender

I know the DailyRollingFileAppender will do it for me.But it does not support the maximum file size when my file size was reached to the specified size.