简体   繁体   中英

Cannot instate the type PagerAdapter? What's wrong?

Hey guys I'm trying to swipe between my activities using PagerAdapter but I'm getting error here's my code, I'm a little new to development of Android, so I'm unable to understand the problem where I've found the solution on Internet. Can anybody tell me how to exactly fix it? Any help would be appreciated, thanks! Here's my code:

PagerAdapter.java :-

package com.example.prototype;

import java.util.List;

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

public class PagerAdapter extends FragmentPagerAdapter {

    private List<Fragment> fragments;

    public PagerAdapter(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();
    }
}

ViewPagerFragmentActivity :-

package com.example.prototype;

import java.util.List;
import java.util.Vector;

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

import com.example.prototype.R;
import com.example.prototype.Games;
import com.example.prototype.Movies;
import com.example.prototype.Songs;

public class ViewPagerFragmentActivity extends FragmentActivity {

    private PagerAdapter mPagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.viewpager_layout);

        this.initialisePaging();
    }

    private void initialisePaging() {

        List<Fragment> fragments = new Vector<Fragment>();
        fragments.add(Fragment.instantiate(this, Games.class.getName()));
        fragments.add(Fragment.instantiate(this, Movies.class.getName()));
        fragments.add(Fragment.instantiate(this, Songs.class.getName()));

        this.mPagerAdapter  = new PagerAdapter(super.getSupportFragmentManager(), fragments);      //Error at this line!!!

        ViewPager pager = (ViewPager) super.findViewById(R.id.viewpager);
        pager.setAdapter(this.mPagerAdapter);
    }
}

Whole LogCat :-

04-25 14:08:12.082: E/vinput-seamless(108): found PS2 device
04-25 14:08:12.082: E/vinput-seamless(108): found seamless mouse device
04-25 14:08:17.726: E/setdpi(286): Setting DPI to 240
04-25 14:08:17.858: E/SurfaceFlinger(116): setOrientation with orientation=0
04-25 14:08:17.858: E/SurfaceFlinger(116): setOrientation orientation=0
04-25 14:08:17.858: E/FramebufferNativeWindow(116): setOrientation with fbDev=0xb85a1af0 fbDev->setOrientation=0xb6003f20 orientation=0
04-25 14:08:18.230: E/local_camera(112): We have a problem with the player connection 22 (Invalid argument)
04-25 14:08:21.930: E/PhonePolicy(117): Could not preload class for phone policy: com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback
04-25 14:08:23.410: E/Genymotion(301): usbOnlinePath not found
04-25 14:08:23.410: E/Genymotion(301): batteryStatusPath not found
04-25 14:08:23.410: E/Genymotion(301): batteryHealthPath not found
04-25 14:08:23.410: E/Genymotion(301): batteryPresentPath not found
04-25 14:08:23.410: E/Genymotion(301): batteryCapacityPath and batteryEnergyPaths not found
04-25 14:08:23.410: E/Genymotion(301): batteryVoltagePath not found
04-25 14:08:23.410: E/Genymotion(301): batteryTemperaturePath not found
04-25 14:08:23.410: E/Genymotion(301): batteryTechnologyPath not found
04-25 14:08:25.174: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:08:25.182: E/libsuspend(301): Error opening /sys/power/autosleep: No such file or directory
04-25 14:08:25.182: E/libsuspend(301): Error opening /sys/power/wakeup_count: Permission denied
04-25 14:08:25.182: E/libsuspend(301): failed to initialize autosuspend
04-25 14:08:25.282: E/WVMExtractor(119): Failed to open libwvm.so
04-25 14:08:25.318: E/WVMExtractor(119): Failed to open libwvm.so
04-25 14:08:25.326: E/EventHub(301): could not get driver version for /dev/input/mouse3, Not a typewriter
04-25 14:08:25.350: E/EventHub(301): could not get driver version for /dev/input/mouse2, Not a typewriter
04-25 14:08:25.366: E/EventHub(301): could not get driver version for /dev/input/mouse1, Not a typewriter
04-25 14:08:25.406: E/EventHub(301): could not get driver version for /dev/input/mouse0, Not a typewriter
04-25 14:08:25.442: E/EventHub(301): could not get driver version for /dev/input/mice, Not a typewriter
04-25 14:08:25.458: E/ConnectivityService(301): Ignoring protectedNetwork 10
04-25 14:08:25.458: E/ConnectivityService(301): Ignoring protectedNetwork 11
04-25 14:08:25.458: E/ConnectivityService(301): Ignoring protectedNetwork 12
04-25 14:08:25.466: E/WifiStateMachine(301): Failed to reload STA firmware java.lang.IllegalStateException: command '2 softap fwreload eth1 STA' failed with '400 2 Softap operation failed (Success)'
04-25 14:08:25.570: E/WifiConfigStore(301): Error parsing configurationjava.io.FileNotFoundException: /data/misc/wifi/ipconfig.txt: open failed: ENOENT (No such file or directory)
04-25 14:08:25.574: E/WifiStateMachine(301): Failed to set frequency band 0
04-25 14:08:26.402: E/GpsLocationProvider(301): no AGPS interface in agps_data_conn_open
04-25 14:08:26.454: E/ActivityThread(423): Failed to find provider info for com.android.inputmethod.latin.dictionarypack
04-25 14:08:26.458: E/BinaryDictionaryGetter(423): Could not find a dictionary pack
04-25 14:08:27.922: E/WVMExtractor(119): Failed to open libwvm.so
04-25 14:08:28.074: E/WVMExtractor(119): Failed to open libwvm.so
04-25 14:08:28.270: E/WVMExtractor(119): Failed to open libwvm.so
04-25 14:08:28.314: E/WVMExtractor(119): Failed to open libwvm.so
04-25 14:08:28.334: E/WVMExtractor(119): Failed to open libwvm.so
04-25 14:08:30.174: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:08:51.417: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:08:56.417: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:09:01.418: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:09:06.417: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:09:11.417: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:09:16.418: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:09:21.417: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:09:26.418: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:09:31.421: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:09:36.421: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:09:41.421: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:09:46.429: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:09:51.430: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:09:56.433: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:10:01.433: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:10:06.434: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:10:11.434: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:10:16.433: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:10:21.433: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:10:26.437: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:10:31.437: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:10:36.437: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:10:41.437: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:10:46.438: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:10:51.437: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:10:56.437: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:11:01.441: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:11:06.441: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:11:11.441: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:11:16.441: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:11:21.441: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:11:26.441: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:11:31.442: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:11:36.445: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:11:41.445: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:11:46.445: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:11:51.445: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:11:56.446: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:12:01.445: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:12:06.445: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:12:11.445: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:12:16.445: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:12:21.445: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:12:26.449: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:12:31.449: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:12:36.449: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:12:41.449: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:12:46.449: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:12:51.450: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:12:56.449: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:13:01.449: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:13:06.453: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:13:11.453: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
04-25 14:13:16.453: E/Genymotion(301): Could not open '/sys/class/power_supply/genymotion_fake_path/present'

you have imported the PagerAdapter from the framework instead of your sublcass. In your ViewPagerFragmentActivity

change from

import android.support.v4.view.PagerAdapter;

to

import com.example.prototype.PagerAdapter;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM