I tried to test the second stage of the Android O Developer preview. After the project was created, I just clicked build and run, but I had no success.
Default generated code for Android by default:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
A compilation error has occurred.
Error:(18, 37) error: reference to findViewById is ambiguous both method findViewById(int) in Activity and method <T>findViewById(int) in AppCompatActivity match where T is a type-variable: T extends View declared in method <T>findViewById(int)
Help me! How to fix this error?
Edit # 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(); } }); }
=> compile Error
Error: (18, 27) error: the reference to findViewById is ambiguous both findViewById (int) methods in Activity and findViewById (int) method according to AppCompatActivity where T is a variable of type: T extends View is declared in findViewById (int) method
This is not a casting issue.
My build.gradle is here.
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' }
I tried Android Oreo Developer Preview 2. And use Android Studio 3.0 Canary version.
android findviewbyid android-o ambiguous
Kihu kwon
source share