0

I have the following generic activity

import android.os.Bundle;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;


public abstract class SingleFragmentActivity extends AppCompatActivity {

   protected abstract Fragment createFragment();
.
.
.

and want to implement

import android.support.v4.app.Fragment;


public class PhotoDisplayActivity extends SingleFragmentActivity {

   @Override
   protected Fragment createFragment() {
       return PhotoDisplayFragment.newInstance();
   }

}

But this is throwing incompatible types: PhotoDisplayFragment cannot be converted to Fragment. Changing the SingleFragmentActivity return type to a PhotoDisplayActivity would obviously defeat the purpose of it being generic.

What am I messing up here?

Thanks, Otterman

Otterman
  • 530
  • 2
  • 5
  • 16
  • You need to be more specific about your errors. Anyway, I would guess that you're mixing up `Fragment` imports. That is, you've got `android.app.Fragment` imported in one place, and `android.support.v4.app.Fragment` in another. – Mike M. May 05 '17 at 02:22
  • Edited to include relevant import statements and error message – Otterman May 05 '17 at 02:35
  • 1
    Look in your `PhotoDisplayFragment` class. You've apparently got `android.app.Fragment` imported there. – Mike M. May 05 '17 at 02:36

0 Answers0