The return type is incompatible with FragmentPagerAdapter.getItem(int)

user2755945

I am following the tutorial here: http://www.javacodegeeks.com/2013/04/android-tutorial-using-the-viewpager.html I get this error in the "Problems": The return type is incompatible with FragmentPagerAdapter.getItem(int) Here is MyPageAdapter.java:

package com.example.loginandregistration;

import java.util.List;

import android.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;


public class MyPageAdapter extends FragmentPagerAdapter { 

private List<Fragment> fragments; 

public MyPageAdapter(FragmentManager fm, List<Fragment> fragments) { 

super(fm); 

this.fragments = fragments; 

} 


 @Override

 public Fragment getItem(int position) {
 return this.fragments.get(position);
 }

 @Override 

public int getCount() { 

return this.fragments.size(); 
  } 
   } 

The error is on line 25:

public Fragment getItem(int position) {

When I open up for the quick fix it gives me the one option to "Change return type of 'getItem(...)' to 'Fragment' but if I do that it gives me an error on the next line and is a continuous loop of those errors going back and forth.

Any help on fixing this really quick is apperciated! Thanks in advance!

Lawrence Choy

Change this line

import android.app.Fragment;

to this line

import android.support.v4.app.Fragment;

This error occurs because you are using FragmentPagerAdapter from the support package, thus it can only returns Fragment class from the support package.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

The return type is incompatible with FragmentPagerAdapter.getItem(int)

From Dev

FragmentPagerAdapter - Incompatible Types

From Dev

Incompatible return type within customList

From Dev

Wildcard for Set in Map - return type incompatible - Why?

From Dev

grails error: return type of getGrailsApplication() is incompatible

From Dev

Swift: Nil is incompatible with return type String

From Dev

The return type is incompatible with <Interface.functionName>

From Dev

Incompatible types: bad return type in lambda expression?

From Dev

"Attempting to use an incompatible return type" with Interface Inheritance

From Dev

incompatible return type from struct function - C

From Dev

Incompatible types in generic return type method (Java)

From Dev

The return type is incompatible with <Interface.functionName>

From Dev

ArgumentException: method return type is incompatible (Mono)

From Dev

Java: compile conflict: return type is incompatible with HATEOAS ResourceSupport.getId

From Dev

Incompatible return type when overriding methods of Generic classes in Java

From Dev

Java8 IntStream incompatible return type for Collections<Integer>.stream()

From Dev

Sealed class in Kotlin, Incompatible types error cannot return parent type

From Dev

Java The return type is incompatible with WebCrawler.visit(Page)

From Java

The type of getMethod() from the type MyClass is String, this is incompatible with the descriptor's return type: U

From Dev

Type specified for TypedQuery is incompatible with query return type [class java.lang.Double]

From Dev

FragmentPagerAdapter does not return the correct view from getItem

From Dev

Incompatible Pivot Type SQL

From Dev

C - Incompatible Pointer Type

From Dev

incompatible type for argument 1

From Dev

Incompatible with parameter of type "LPCWSTR"

From Dev

nested part of incompatible type

From Dev

incompatible vs incomparable type

From Dev

incompatible types with type variables

From Dev

incompatible type C error?

Related Related

  1. 1

    The return type is incompatible with FragmentPagerAdapter.getItem(int)

  2. 2

    FragmentPagerAdapter - Incompatible Types

  3. 3

    Incompatible return type within customList

  4. 4

    Wildcard for Set in Map - return type incompatible - Why?

  5. 5

    grails error: return type of getGrailsApplication() is incompatible

  6. 6

    Swift: Nil is incompatible with return type String

  7. 7

    The return type is incompatible with <Interface.functionName>

  8. 8

    Incompatible types: bad return type in lambda expression?

  9. 9

    "Attempting to use an incompatible return type" with Interface Inheritance

  10. 10

    incompatible return type from struct function - C

  11. 11

    Incompatible types in generic return type method (Java)

  12. 12

    The return type is incompatible with <Interface.functionName>

  13. 13

    ArgumentException: method return type is incompatible (Mono)

  14. 14

    Java: compile conflict: return type is incompatible with HATEOAS ResourceSupport.getId

  15. 15

    Incompatible return type when overriding methods of Generic classes in Java

  16. 16

    Java8 IntStream incompatible return type for Collections<Integer>.stream()

  17. 17

    Sealed class in Kotlin, Incompatible types error cannot return parent type

  18. 18

    Java The return type is incompatible with WebCrawler.visit(Page)

  19. 19

    The type of getMethod() from the type MyClass is String, this is incompatible with the descriptor's return type: U

  20. 20

    Type specified for TypedQuery is incompatible with query return type [class java.lang.Double]

  21. 21

    FragmentPagerAdapter does not return the correct view from getItem

  22. 22

    Incompatible Pivot Type SQL

  23. 23

    C - Incompatible Pointer Type

  24. 24

    incompatible type for argument 1

  25. 25

    Incompatible with parameter of type "LPCWSTR"

  26. 26

    nested part of incompatible type

  27. 27

    incompatible vs incomparable type

  28. 28

    incompatible types with type variables

  29. 29

    incompatible type C error?

HotTag

Archive