android - 无法设置 PagerAdapter 类型?怎么了?

标签 android android-activity fragment fragmentpageradapter

嘿伙计们,我正在尝试使用 PagerAdapter 在我的 Activity 之间滑动,但我在我的代码中遇到错误,我对 Android 开发有点陌生,所以我无法了解我在 Internet 上找到解决方案的问题。谁能告诉我如何准确修复它?任何帮助将不胜感激,谢谢!这是我的代码:

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);
    }
}

整个 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'

最佳答案

您已经从框架而不是子类中导入了 PagerAdapter。在你的 ViewPagerFragmentActivity

改变自

import android.support.v4.view.PagerAdapter;

import com.example.prototype.PagerAdapter;

关于android - 无法设置 PagerAdapter 类型?怎么了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29866156/

相关文章:

android - 由于 SELinux,Systrace 不再适用于 Marshmallow 中的 Nexus 6?有人让它重新工作了吗?

在 Activity 的 onCreate 中调用 show() 时,Android DialogFragment 不显示

java - 两个 fragment 之间共享一个连接

屏幕旋转后Android fragment 重叠

java - Android linphone.jar错误:Execution failed for task ':app:dexDebug'

android - 查看 Firebase 上的 childEventListener 是否已完成所有数据的加载

java - 使用for循环为多个 ImageView 设置图像资源

android - 不记录广告曝光。没有活跃的 Activity 。 'Google Admob RewardedVideo'

android-activity - 将 SalesForce Chatter 数据迁移到 Dynamics CRM 2011 中的 Activity 源

android - 使用 add() 方法添加 fragment 不会隐藏以前的 fragment