Instantiate PagerAdapter Android
Asked Answered
B

2

5

2Hi guys I'm trying to build an app using a horizontal pager and the support package for Android. I've made this exact code compile in another project but the last line of the second code example is not letting me compile. Eclipse is saying Cannot instantiate the type PagerAdapter

My imports

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;

My code

List<Fragment> fragments = new Vector<Fragment>();
    fragments.add(Fragment.instantiate(this, Tab1.class.getName()));
    fragments.add(Fragment.instantiate(this, Tab2.class.getName()));
    fragments.add(Fragment.instantiate(this, Tab3.class.getName()));
    this.mPagerAdapter  = new PagerAdapter(super.getSupportFragmentManager(), fragments);

Do you think there is something wrong with my imports or project set up - let me know if you need more information. This code has worked in other projects.

Thanks

Biannulate answered 16/3, 2012 at 11:18 Comment(1)
PagerAdapter is an abstract class, and can therefore not be instantiated. See developer.android.com/reference/android/support/v4/view/….Misinform
B
10

PagerAdapter is an abstract class – you cannot instantiate it. You have to create a new class that inherits from PagerAdapter and use that instead.

Bile answered 16/3, 2012 at 11:43 Comment(1)
I have create a new class PagerAdapter, even though it shows the same error. @HerrmannVouch
H
2

Just create a new class that inherits from PagerAdapter and use it instead.

NB: Don't forget to remove the initial import "import android.support.v4.view.PagerAdapter;" and import the newly created class.

Himmler answered 4/7, 2016 at 9:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.