日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

android的findviewbyid,Android O预览findViewById编译错误

發(fā)布時(shí)間:2023/12/19 Android 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android的findviewbyid,Android O预览findViewById编译错误 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我試圖測(cè)試

Android O Developer Preview的第二階段.

項(xiàng)目創(chuàng)建后,我只是點(diǎn)擊了構(gòu)建并運(yùn)行但我沒有任何成功.

Android默認(rèn)生成的代碼如下:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

發(fā)生編譯錯(cuò)誤.

Error:(18, 37) error: reference to findViewById is ambiguous

both method findViewById(int) in Activity and method

findViewById(int) in AppCompatActivity match

where T is a type-variable:

T extends View declared in method findViewById(int)

幫我!我該如何解決這個(gè)錯(cuò)誤?

編輯#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();

}

});

}

=>編譯錯(cuò)誤

錯(cuò)誤:(18,27)錯(cuò)誤:對(duì)findViewById的引用不明確

Activity中的方法findViewById(int)和AppCompatActivity中的方法findViewById(int)匹配

其中T是一個(gè)類型變量:

T擴(kuò)展方法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'

}

我嘗試過Android Oreo Developer Preview 2.

并使用Android Studio 3.0 Canary版.

總結(jié)

以上是生活随笔為你收集整理的android的findviewbyid,Android O预览findViewById编译错误的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。