7

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?

Dinal Koyani
  • 455
  • 3
  • 6
android
  • 2,942
  • 1
  • 15
  • 20

4 Answers4

2

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

Northern Poet
  • 1,955
  • 1
  • 12
  • 17
  • hi @Northern Poet, i just updated 26 sdk tools to 27 and it runs perfectly without removing anything in code – android Nov 01 '17 at 06:55
2

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

hungryghost
  • 9,463
  • 3
  • 23
  • 36
0

If doing invalidate caches/restart, then re-sync gradle, does not work, restart the computer, it worked for me.

Hernâni Pereira
  • 312
  • 4
  • 19
0

I was working with a new project and in gradle files did not have version numbers set in them, there was "N" across minsdkversion and targetsdkversion, changing to desired sdk version solved the problem

Meenohara
  • 314
  • 4
  • 9