Android O预览findViewById编译错误

Kih*_*won 8 android ambiguous findviewbyid android-8.0-oreo

我试图测试Android O Developer Preview的第二阶段.在项目创建之后,我只是点击了构建并运行但我没有任何成功.

Android默认生成的代码如下:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
Run Code Online (Sandbox Code Playgroud)

发生编译错误.

Error:(18, 37) error: reference to findViewById is ambiguous
both method findViewById(int) in Activity and method 
<T>findViewById(int) in AppCompatActivity match
where T is a type-variable:
T extends View declared in method <T>findViewById(int)
Run Code Online (Sandbox Code Playgroud)

帮我!我该如何解决这个错误?

编辑#1

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

=>编译错误

错误:(18,27)错误:对findViewById的引用不明确,Activity中的方法findViewById(int)和AppCompatActivity中的方法findViewById(int)匹配,其中T是类型变量:T extends在方法findViewById(int)中声明的View

这不是铸造问题.

我的build.gradle就在这里.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-O'
    buildToolsVersion "26.0.0-rc2"
    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 16
        targetSdkVersion 'O'
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.0.0-beta1'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:26.0.0-beta1'
}
Run Code Online (Sandbox Code Playgroud)

我尝试了Android Oreo Developer Preview 2.并使用Android Studio 3.0 Canary版.

Ben*_*ove -1

我相信他们更改了 findViewById 的方法签名,以便您不再需要强制转换。尝试将该行代码更改为

Toolbar toolbar = findViewById(R.id.toolbar);
Run Code Online (Sandbox Code Playgroud)