Type mismatch: cannot convert from ListFragment to Fragment

Al Lelopath

I have a TabsPagerAdapter class as below. The classes FirstFragment, SecondFragment and ThirdFragment each extended Fragment and all was well. Then I changed SecondFragment to extend ListFragment and now I get compile error:
Type mismatch: cannot convert from SecondFragment to Fragment

ListFragment extends Fragment, so in my mind. this shouldn't be a problem.
What do I do?

Import in SecondFragment is:

import android.app.ListFragment;

Class:

public class TabsPagerAdapter extends FragmentPagerAdapter {

    private Context mContext;

    public TabsPagerAdapter(FragmentManager fragmentManager, Context context) {
        super(fragmentManager);
        mContext = context;
    }

    @Override
    public Fragment getItem(int index) {

        Fragment returnFragment = null;

        switch (index) {
        case 0:
            returnFragment = new FirstFragment(mContext);
            break;
        case 1:
            returnFragment=  new SecondFragment(mContext);
            break;
        case 2:
            returnFragment = new ThirdFragment(mContext);
            break;
        }

        return returnFragment;
    }

    @Override
    public int getCount() {
        // get item count - equal to number of tabs
        return 3;
    }
}
Blackbelt

The issue is usually due of a mismatch between the import in the different classes. You probably have the native Fragment in one class and the one from the support library in the other. Fix the imports and it will work. check the imports. Also remove the constructor that takes a parameter in your Fragment subclasses. The system wants a public empty constructor (aka default constructor). If you need a context, you can use getActivity()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Type Type mismatch: cannot convert from RegisterFragment to Fragment

From Dev

Type mismatch: cannot convert from FragmentOne to Fragment when create FragmentOne in seperate class?

From Dev

Type missmatch cannot convert from Fragment to fragment

From Dev

Type mismatch: cannot convert from boolean to int

From Dev

Type mismatch: cannot convert from long to int

From Dev

type mismatch: cannot convert from double to Double

From Dev

Type mismatch cannot convert from String to String[]

From Dev

Type mismatch: cannot convert from Scanner to boolean

From Dev

Type mismatch: cannot convert from void to Integer

From Dev

Type mismatch: cannot convert from int to TextView

From Dev

Type mismatch: cannot convert from void to int

From Dev

Type mismatch : cannot convert from double[][] to double[]

From Dev

Type mismatch: cannot convert from boolean to double

From Dev

Type mismatch cannot convert from String to String[]

From Dev

Type mismatch: cannot convert from double to double[]

From Dev

Type mismatch: cannot convert from void to Thread

From Dev

Type mismatch: cannot convert from element type Object to Cookie

From Dev

type mismatch cannot convert from element type object to string

From Dev

Java - Type mismatch: cannot convert from element type Object to String

From Dev

type mismatch cannot convert from element type object to string

From Dev

Type mismatch: cannot convert from element type Object to Cookie

From Dev

Java - Type mismatch: cannot convert from element type Object to String

From Dev

Type mismatch: cannot convert from element type Object to List

From Dev

Type mismatch: cannot convert from Class<capture#1-of ?> to Class<?>[]

From Dev

Type mismatch: cannot convert from Class<Parameterized> to Class<? extends Runner>

From Dev

Type mismatch: cannot convert from java.lang.String to String

From Dev

Type mismatch: cannot convert from Object to Class object

From Dev

Java generics. Type mismatch: cannot convert from object to

From Dev

GWT UIBinder Type mismatch: cannot convert from ImageResource to Image

Related Related

  1. 1

    Type Type mismatch: cannot convert from RegisterFragment to Fragment

  2. 2

    Type mismatch: cannot convert from FragmentOne to Fragment when create FragmentOne in seperate class?

  3. 3

    Type missmatch cannot convert from Fragment to fragment

  4. 4

    Type mismatch: cannot convert from boolean to int

  5. 5

    Type mismatch: cannot convert from long to int

  6. 6

    type mismatch: cannot convert from double to Double

  7. 7

    Type mismatch cannot convert from String to String[]

  8. 8

    Type mismatch: cannot convert from Scanner to boolean

  9. 9

    Type mismatch: cannot convert from void to Integer

  10. 10

    Type mismatch: cannot convert from int to TextView

  11. 11

    Type mismatch: cannot convert from void to int

  12. 12

    Type mismatch : cannot convert from double[][] to double[]

  13. 13

    Type mismatch: cannot convert from boolean to double

  14. 14

    Type mismatch cannot convert from String to String[]

  15. 15

    Type mismatch: cannot convert from double to double[]

  16. 16

    Type mismatch: cannot convert from void to Thread

  17. 17

    Type mismatch: cannot convert from element type Object to Cookie

  18. 18

    type mismatch cannot convert from element type object to string

  19. 19

    Java - Type mismatch: cannot convert from element type Object to String

  20. 20

    type mismatch cannot convert from element type object to string

  21. 21

    Type mismatch: cannot convert from element type Object to Cookie

  22. 22

    Java - Type mismatch: cannot convert from element type Object to String

  23. 23

    Type mismatch: cannot convert from element type Object to List

  24. 24

    Type mismatch: cannot convert from Class<capture#1-of ?> to Class<?>[]

  25. 25

    Type mismatch: cannot convert from Class<Parameterized> to Class<? extends Runner>

  26. 26

    Type mismatch: cannot convert from java.lang.String to String

  27. 27

    Type mismatch: cannot convert from Object to Class object

  28. 28

    Java generics. Type mismatch: cannot convert from object to

  29. 29

    GWT UIBinder Type mismatch: cannot convert from ImageResource to Image

HotTag

Archive