Cannot call ViewPagerAdapter constructor in android

Abstract: Fix the Cannot call ViewPagerAdapter constructor error by extending FragmentStateAdapter or FragmentPagerAdapter with correct arguments and implementing required abstract methods.

Created: 2026-07-30 by

Resolve the "Cannot call ViewPagerAdapter constructor" error by ensuring your adapter class extends FragmentStateAdapter or FragmentPagerAdapter and that you are instantiating it with a valid FragmentActivity or FragmentManager. This typically occurs when passing an incorrect context type or failing to implement required abstract methods like getItem() and getCount().

Understanding the Adapter Hierarchy

In modern Android development, ViewPager2 has largely replaced the older ViewPager. Consequently, the adapter classes have changed significantly. The most common source of this constructor error is attempting to use legacy patterns with new APIs or vice versa. If you are using ViewPager2, your adapter must extend FragmentStateAdapter. This class requires a specific constructor signature that accepts a FragmentActivity as its primary argument. If you are still using the original ViewPager, you should extend FragmentPagerAdapter or FragmentStatePagerAdapter. These classes require a FragmentManager in their constructor. Mixing these up leads to immediate compilation failures because the constructor signatures do not match what you are providing. For instance, trying to pass a generic Context to a constructor that expects an Activity will fail. It is crucial to identify which ViewPager implementation your project relies on before writing the adapter code.

Correct Constructor Signatures

When extending FragmentStateAdapter for ViewPager2, the constructor must look like this:
public class ViewPagerAdapter extends FragmentStateAdapter {
    public ViewPagerAdapter(@NonNull FragmentActivity activity) {
        super(activity);
    }
}
Notice that we pass activity to the super constructor. We cannot pass this if we are inside the Activity itself unless we are careful about initialization order, but typically we pass the activity reference directly. If you try to write super(this) inside an Activity, it might compile if the Activity is a subclass of FragmentActivity, but it is often cleaner to just pass the activity instance. However, if you are defining the adapter as an inner class, ensure the outer class is indeed an Activity. For the legacy ViewPager, the signature is different:
public class LegacyPagerAdapter extends FragmentPagerAdapter {
    private final List fragmentList;

    public LegacyPagerAdapter(@NonNull FragmentManager fm, int behavior, List fragments) {
        super(fm, behavior);
        this.fragmentList = fragments;
    }
}
Here, the second argument is the behavior flag, such as BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT. If you omit this or pass an integer where an enum is expected, or vice versa, the compiler will reject the constructor call. Always check the exact number of arguments required by the parent class.

Common Implementation Mistakes

One frequent mistake is failing to implement the mandatory abstract methods. Both FragmentStateAdapter and FragmentPagerAdapter require you to override getItem(int position) and getCount(). If you forget these, the class remains abstract, and you cannot instantiate it. The compiler will explicitly tell you that the class is not abstract and does not override abstract method getItem(int). Another issue arises from incorrect imports. Developers often import androidx.viewpager.widget.ViewPager while intending to use androidx.viewpager2.widget.ViewPager2. These are entirely different libraries with different adapters. Ensure your build.gradle file includes the correct dependency. For ViewPager2, you need:
implementation 'androidx.viewpager2:viewpager2:1.0.0'
Without this library, any reference to FragmentStateAdapter will result in a "cannot find symbol" error, which can be misinterpreted as a constructor issue if you are trying to fallback to old code.

Handling Fragment Lists

You must provide the fragments to the adapter. In FragmentStateAdapter, you typically store a list of fragments or IDs. A common pattern is to pass a list of fragment instances to the adapter's constructor. However, be cautious with object lifecycles. If you create fragments in the Activity and pass them to the adapter, ensure they are properly detached and reattached by the system.
public ViewPagerAdapter(@NonNull FragmentActivity activity, List fragments) {
    super(activity);
    this.fragments = fragments;
}

@NonNull
@Override
public Fragment getItem(int position) {
    return fragments.get(position);
}

@Override
public int getCount() {
    return fragments.size();
}
In this example, we store the fragments in a member variable. The getItem method returns the fragment at the specified position. This simple structure resolves most constructor-related issues because it adheres strictly to the FragmentStateAdapter contract.

Debugging Steps

If you still encounter errors, follow these diagnostic steps. First, verify the superclass. Right-click on your adapter class name and choose "Go To Superclass". Ensure it is either FragmentStateAdapter or FragmentPagerAdapter. Second, check the constructor parameters. Compare them side-by-side with the official documentation for the specific version of AndroidX you are using. Third, clean and rebuild your project. Sometimes IDE caches cause false positives regarding missing symbols. It is also worth noting that you cannot use addFragments or similar non-standard methods. Stick to the standard lifecycle management provided by the adapter. If you need dynamic updates, modify the underlying list and call notifyDataSetChanged().

Frequently Asked Questions

Why does my adapter say it is not abstract?

This error means you have forgotten to implement the required abstract methods like getItem() and getCount(). You must define these methods in your adapter class to make it concrete and instantiable.

Can I use Context instead of FragmentActivity?

No, FragmentStateAdapter specifically requires a FragmentActivity. Passing a generic Context will cause a compilation error because the adapter needs access to the fragment manager associated with the activity.

What is the difference between FragmentPagerAdapter and FragmentStateAdapter?

FragmentPagerAdapter keeps all created fragments in memory, which is good for a small number of tabs. FragmentStateAdapter destroys fragments that are not visible, saving memory for larger datasets. Use FragmentStateAdapter with ViewPager2.

How do I fix "cannot find symbol" for FragmentStateAdapter?

Ensure you have added the viewpager2 dependency in your build.gradle file and that you are importing from androidx.viewpager2.app.FragmentStateAdapter.

Do I need to manage fragment transactions manually?

No, the adapter handles fragment transactions automatically. You only need to provide the fragments in getItem() and report the count via getCount().

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More