尝试使用FragmentActivity时无法访问ActivityCompatApi23 [英] Cannot acces ActivityCompatApi23 when trying to use FragmentActivity

查看:232
本文介绍了尝试使用FragmentActivity时无法访问ActivityCompatApi23的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的智能手表上使用ViewPager,但是在尝试重建/运行/调试我的应用程序时,我总是收到错误消息.我正在使用FragmentActivity,这是发生错误的地方.我搜索了stackoverflow和教程网站,看可能是什么问题,并且很多结果都与build.gradle文件有关.但是我几乎尝试了所有偶然发现的事情,但是错误一次都没有改变.

I'm trying to use a ViewPager on my smartwatch, but I keep getting an error when trying to rebuild/run/debug my application. I'm using a FragmentActivity, which is where the error occurs. I searched stackoverflow and tutorial websites to see what could be the problem, and a lot of results are related to the build.gradle files. However I tried pretty much everything I stumbled upon, but the error didn't change once.

错误:

Error: Cannot acces ActivityCompatApi23

此行发生错误,来自下面的代码.

The error happens on this line, coming from the piece of code below.

public class WearMainActivity extends FragmentActivity {

WearMainActivity.java

package be.ehb.dt.finalwork_lievenluyckx_v001;

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 java.util.List;
import java.util.Vector;

/**
 * Created by Lieven on 14/08/17.
 */

public class WearMainActivity extends FragmentActivity {


    private PagerAdapter pagerAdapter;

    /* (non-Javadoc)
      * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
      */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.viewpager);
        //initialsie the pager
        initialisePaging();
    }

    /**
     * Initialise the fragments to be paged
     */
    private void initialisePaging() {

        List<Fragment> fragments = new Vector<Fragment>();
        fragments.add(Fragment.instantiate(this, Monitor.class.getName()));
        fragments.add(Fragment.instantiate(this, CurrentSongOverviewWear.class.getName()));
        this.pagerAdapter  = new MyPagerAdapter(getSupportFragmentManager(), fragments);

        ViewPager pager = (ViewPager) findViewById(R.id.viewpager_container);
        pager.setAdapter(this.pagerAdapter);
    }
}

build.gradle(WEAR)

apply plugin: 'com.android.application'

android {
    allprojects {
        repositories {
            jcenter()
            maven {
                url "https://maven.google.com"
            }
        }
    }

    compileSdkVersion 25
    buildToolsVersion "25.0.1"
    defaultConfig {
        applicationId "be.ehb.dt.finalwork_lievenluyckx_v001"
        minSdkVersion 25
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    compile 'com.android.support:wear:26.0.0'
    compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'com.google.android.support:wearable:2.0.3'
    compile 'com.google.android.gms:play-services:11.0.4'
    provided 'com.google.android.wearable:wearable:2.0.3'
    compile 'com.android.support:support-v4:26.0.0-alpha1'
}

推荐答案

按照Eugen Pechanec的解释(作为原始帖子的下方注释),为我解决了该问题:

Following Eugen Pechanec's explanation (as a comment below the original post) fixed the problem for me:

所有支持库必须为相同版本.如果您的编译SDK是 25,是25.4.0.如果您的编译SDK为26,则为26.0.1.不要混 他们.

All support libraries need to be same version. If your compile SDK is 25, it's 25.4.0. If your compile SDK is 26, it's 26.0.1. Don't mix them.

这篇关于尝试使用FragmentActivity时无法访问ActivityCompatApi23的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆