Bug 28128 - [Android] 'Java.Lang.NoSuchMethodError' attempting to invoke View.IsAttachedToWindow in versions earlier than KitKat
Summary: [Android] 'Java.Lang.NoSuchMethodError' attempting to invoke View.IsAttachedT...
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.20.0
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Larry O'Brien
Depends on:
Reported: 2015-03-17 15:11 UTC by Dominic N [MSFT]
Modified: 2015-03-17 16:59 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Repro project (39.48 KB, application/zip)
2015-03-17 15:11 UTC, Dominic N [MSFT]

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Dominic N [MSFT] 2015-03-17 15:11:50 UTC
Created attachment 10388 [details]
Repro project

## Overview

We have a report of a customer experiencing an issue with a fatal crash with a 'Java.Lang.NoSuchMethodError' when attempting to invoke View.IsAttachedToWindow in Android API versions under 4.4. The following code is what is being used to generate said error:
public void RemoveNotification(CustomNotification notification) {
    var windowManager = notification.WindowManager;
    if (windowManager != null && notification.View.IsAttachedToWindow /* THROWS EXCEPTION */) {
        try {
            windowManager.RemoveView (notification.View);
        } catch (IllegalStateException) {  }
        // Queue up display notification
       SendMessageDelayed (notification, Messages.DisplayCustomToast, 500);

(CustomNotification is a custom "toast" type)

Please note the related bug another customer reported in Xamarin.Forms.

## Steps to reproduce

1. Download and deploy sample app to KitKat device
2. Click button
3. Repeat steps 1. and 2. for a device with Android version earlier than KitKat

## Expected results

Clicking the button shows a toast and raises no exceptions.

## Actual results

Clicking the button throws a 'Java.Lang.NoSuchMethodError' in versions of Android earlier than KitKat.

## Additional information

Stack trace: https://gist.github.com/heiligerdankgesang/ff89eec225d605095377

## Version information

=== Xamarin Studio ===

Version 5.8 (build 443)
Installation UUID: f1732b88-1ebe-448d-89a1-fa075f56d19b
Mono 3.12.1 ((detached/b7764aa)
GTK+ 2.24.23 (Raleigh theme)

Package version: 312010000

=== Apple Developer Tools ===

Xcode 6.1.1 (6611)
Build 6A2008a

=== Xamarin.iOS ===

Version: (Enterprise Edition)
Hash: ccfcd59
Build date: 2015-03-10 02:20:32-0400

=== Xamarin.Android ===

Version: (Enterprise Edition)
Android SDK: /Users/<username>/Library/Developer/android-sdk-mac_x86
Supported Android versions:
2.1 (API level 7)
2.2 (API level 8)
2.3 (API level 10)
3.1 (API level 12)
4.0 (API level 14)
4.0.3 (API level 15)
4.1 (API level 16)
4.2 (API level 17)
4.3 (API level 18)
4.4 (API level 19)
4.4.87 (API level 20)
5.0 (API level 21)
Java SDK: /usr
java version "1.7.0_76"
Java(TM) SE Runtime Environment (build 1.7.0_76-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.76-b04, mixed mode)

=== Xamarin Android Player ===

Not Installed

=== Xamarin.Mac ===

Not Installed

=== Build Information ===

Release ID: 508000443
Git revision: 73883239470cbe8e261c94d95f7c3d0452fd393b
Build date: 2015-03-10 07:22:51-04
Xamarin addins: a2ff7b617f09d9c45d8bbf3d010b5db0d7d36100

=== Operating System ===

Mac OS X 10.10.2
Darwin mac-2.local 14.1.0 Darwin Kernel Version 14.1.0
Thu Feb 26 19:26:47 PST 2015
root:xnu-2782.10.73~1/RELEASE_X86_64 x86_64
Comment 1 Dominic N [MSFT] 2015-03-17 15:23:35 UTC
I have confirmed this locally using a Moto X on 4.2.2.
Comment 2 Jonathan Pryor 2015-03-17 15:25:10 UTC
> We have a report of a customer experiencing an issue with a fatal crash with a
> 'Java.Lang.NoSuchMethodError' when attempting to invoke View.IsAttachedToWindow
> in Android API versions under 4.4.

That would be because View.IsAttachedToWindow() was added in API-19 (Android v4.4), and thus doesn't exist in prior Android versions:


The one oddity here is that our imported documentation says otherwise, and is thus erroneous:

> Since: Added in API level 1

If you built against a lower $(TargetFrameworkVersion), the compiler would generate an error that the member doesn't exist.
Comment 3 Larry O'Brien 2015-03-17 15:29:56 UTC
I'm going to make a manual edit of the android docs today so that customers don't see the exact error, but will not close the bug until the import process is fixed.
Comment 4 Larry O'Brien 2015-03-17 16:09:38 UTC
(problem seems to extend across many (probably all) elements added in Level 19. Curiously, the @since tag is not used in the source JavaDoc, so not clear what the canonical source of this should be.)
Comment 5 David Barrett 2015-03-17 16:59:20 UTC
I'm embarrassed to ask this because given the amount of time I've been using Xamarin, it seems naive, but:

I'm presuming that this member (View.IsAttachedToWindow) shouldn't show up since we target 5.0 but our minimum is 4.0, and since this API was added in 19 (4.4), it won't be available on all platforms?  I.e., only if we were to update the minimum to 4.4, it should show, yes?