JavaEar 专注于收集分享传播有价值的技术资料

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?

2个回答

    最佳答案
  1. 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

  2. 参考答案2
  3. If you recently updated your project to API 26, try doing invalidate caches/restart, then re-sync gradle.