单页面网站可以做自适应网站吗,wordpress网站好用吗,十大舆情网站,手机版龙岩kk网我试图测试Android O Developer Preview的第二阶段。 项目创建后#xff0c;我只是点击了构建并运行但我没有任何成功。Android默认生成的代码如下#xff1a;Toolbar toolbar (Toolbar) findViewById(R.id.toolbar);发生编译错误。Error:(18, 37) error: reference to find…我试图测试Android O Developer Preview的第二阶段。 项目创建后我只是点击了构建并运行但我没有任何成功。Android默认生成的代码如下Toolbar toolbar (Toolbar) findViewById(R.id.toolbar);发生编译错误。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)帮我 我该如何解决这个错误编辑1Override 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(); } }); }编译错误错误(18,27)错误对findViewById的引用不明确Activity中的方法findViewById(int)和AppCompatActivity中的方法findViewById(int)匹配其中T是typesvariablesT 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 }我尝试了Android Oreo Developer Preview 2.并使用Android Studio 3.0 Canary版。你的build.gradle看起来不错但是编译器似乎仍然需要使用supportLib 26来编译旧的compileSdkVersion (25或更低版本)。尝试同步gradle和Build- Clean Project 。 如果这没有帮助 File- Invalidate Cache / Restart应该做的事情……findViewById的方法签名随着API级别25的引入而改变以支持generics并删除丑陋的转换新方法签名public T findViewById (int id);与旧的相比public View findViewById(int id);因此将您的代码更改为Toolbar toolbar findViewById(R.id.toolbar);参考 查看| Android开发人员当我的compileSdkVersion为27并且buildToolsVersion不是27时我遇到了同样的问题。将它们更改为compileSdkVersion 27 buildToolsVersion“27.0.0”我认为当buildToolsVersion比compileSdkVersion更旧时会发生这种情况。我相信他们改变了findViewById的方法签名这样你就不再需要强制转换了。 尝试将该行代码更改为Toolbar toolbar findViewById(R.id.toolbar);