incompatible types: HomeFragment cannot be converted to Fragment in Android

Lior

I'm getting an error in this part of code:

private void displayView(int position) {
    // update the main content by replacing fragments
    Fragment fragment = null;
    switch (position) {
        case 0:
            fragment = new HomeFragment();
            break;
        case 1:
            fragment =new FindPeopleFragment();
            break;
        case 2:
            fragment = new PhotosFragment();
            break;
        case 3:
            fragment = new CommunityFragment();
            break;
        case 4:
            fragment = new PagesFragment();
            break;
        case 5:
            fragment = new WhatsHotFragment();
            break;

        default:
            break;
    }

    if (fragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.frame_container, fragment).commit();

        // update selected item and title, then close the drawer
        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        setTitle(navMenuTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);
    } else {
        // error in creating fragment
        Log.e("MainActivity", "Error in creating fragment");
    }
}

I get

error: incompatible types: HomeFragment cannot be converted to Fragment

this is the imports:

package liorsiag.lgbt;
import android.app.FragmentManager;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import java.util.ArrayList;

and this is the class title:

public class MainActivity extends FragmentActivity {
    private DrawerLayout mDrawerLayout;
    private ListView mDrawerList;
    private ActionBarDrawerToggle mDrawerToggle;

No matter what I've tried I still get this error

I've tried a lot of navigation drawer tutorials, but none of them seem to work.

zozelfelfo

This seems to be an import problem.

When using getFragmentMangager(), make sure that your Fragment classes extend android.app.Fragment class.

If by any chance you are using android.support.v4.app.Fragment (see your imports), then you need to use getSupportFragmentManager() instead

Hope it helps

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

incompatible types: FragmentDark cannot be converted to Fragment in Android

From Dev

HomeFragment cannot be converted to Fragment

From Dev

How to fix the error: incompatible types: MenuFragment cannot be converted to Fragment in android?

From Dev

Incompatible types: Fragment cannot be converted to NavigationDrawerFragment

From Dev

Android Studio: error: incompatible types: MainActivity cannot be converted to Application

From Dev

incompatible types: Node cannot be converted to Tab

From Java

incompatible types: int cannot be converted to T

From Java

Java incompatible types: int cannot be converted to int[]

From Java

Java : incompatible types; int cannot be converted to string

From Dev

Error: incompatible types: double cannot be converted to JTextField

From Dev

Error: incompatible types: Object cannot be converted to char

From Dev

incompatible types: void cannot be converted to int

From Dev

incompatible types: BigInteger cannot be converted to int

From Dev

Incompatible types: Object cannot be converted to ParseObject

From Dev

Java incompatible types: int cannot be converted to int[]

From Dev

incompatible types: char[] cannot be converted to CharSequence

From Dev

error: incompatible types: MainFragment cannot be converted to Activity

From Dev

Error: incompatible types: Object cannot be converted to char

From Dev

incompatible types: BigInteger cannot be converted to int

From Dev

incompatible types: Object cannot be converted to CoreLabel

From Dev

Java JComboBox Incompatible Types: Cannot be converted to string

From Dev

error: incompatible types: Object cannot be converted to MyClass

From Dev

incompatible types: String[] cannot be converted to String

From Dev

incompatible types: MainActivity cannot be converted to LifecycleOwner

From Dev

error: incompatible types: int[][] cannot be converted to int

From Dev

Android Fragment manager incompatible types

From Dev

Error incompatible types: android.app.FragmentManager cannot be converted to android.support.v4.app.FragmentManager

From Dev

Incompatible types: android.app.FragmentManager cannot be converted to android.support.v4.app.FragmentManager

From Dev

Android Studio Fragment Incompatible types Error

Related Related

  1. 1

    incompatible types: FragmentDark cannot be converted to Fragment in Android

  2. 2

    HomeFragment cannot be converted to Fragment

  3. 3

    How to fix the error: incompatible types: MenuFragment cannot be converted to Fragment in android?

  4. 4

    Incompatible types: Fragment cannot be converted to NavigationDrawerFragment

  5. 5

    Android Studio: error: incompatible types: MainActivity cannot be converted to Application

  6. 6

    incompatible types: Node cannot be converted to Tab

  7. 7

    incompatible types: int cannot be converted to T

  8. 8

    Java incompatible types: int cannot be converted to int[]

  9. 9

    Java : incompatible types; int cannot be converted to string

  10. 10

    Error: incompatible types: double cannot be converted to JTextField

  11. 11

    Error: incompatible types: Object cannot be converted to char

  12. 12

    incompatible types: void cannot be converted to int

  13. 13

    incompatible types: BigInteger cannot be converted to int

  14. 14

    Incompatible types: Object cannot be converted to ParseObject

  15. 15

    Java incompatible types: int cannot be converted to int[]

  16. 16

    incompatible types: char[] cannot be converted to CharSequence

  17. 17

    error: incompatible types: MainFragment cannot be converted to Activity

  18. 18

    Error: incompatible types: Object cannot be converted to char

  19. 19

    incompatible types: BigInteger cannot be converted to int

  20. 20

    incompatible types: Object cannot be converted to CoreLabel

  21. 21

    Java JComboBox Incompatible Types: Cannot be converted to string

  22. 22

    error: incompatible types: Object cannot be converted to MyClass

  23. 23

    incompatible types: String[] cannot be converted to String

  24. 24

    incompatible types: MainActivity cannot be converted to LifecycleOwner

  25. 25

    error: incompatible types: int[][] cannot be converted to int

  26. 26

    Android Fragment manager incompatible types

  27. 27

    Error incompatible types: android.app.FragmentManager cannot be converted to android.support.v4.app.FragmentManager

  28. 28

    Incompatible types: android.app.FragmentManager cannot be converted to android.support.v4.app.FragmentManager

  29. 29

    Android Studio Fragment Incompatible types Error

HotTag

Archive