Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous method call. Both findViewById (int) in AppCompactActivity and Activity

I refer this link Error : Ambiguous method call. Both findViewById (int) in AppCompactActivity and Activity to solve but there is no import android.app.Activity and also if I convert my import android.support.v7.app.AppCompatActivity into android.app.Activity then the error goes but I want to use AppCompatActivity.

I also update all libraries in SDK and also invalidate and restart but nothing works.

why this error occurs and how to solve this?

like image 987
android Avatar asked Nov 01 '17 05:11

android


2 Answers

I guess you have something like that

ViewClass view = (ViewClass)findViewById(R.id.view);

in your code and you'd updated API level? If so, change your code to

ViewClass view = findViewById(R.id.view); // without redundant cast

The findViewById method signature was changed in API 25, please refer to SDK

like image 104
Northern Poet Avatar answered Oct 03 '22 19:10

Northern Poet


If you recently updated your project to API 26, try doing invalidate caches/restart, then re-sync gradle.

like image 24
hungryghost Avatar answered Oct 03 '22 18:10

hungryghost