Bug 4821 - Application crashes when using Key event on KeyboardView
Summary: Application crashes when using Key event on KeyboardView
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.1.x
Hardware: Macintosh Mac OS
: --- critical
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-05-02 10:20 UTC by Chris Hardy [MSFT]
Modified: 2012-05-02 22:39 UTC (History)
2 users (show)

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

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:
Status:
RESOLVED FIXED

Description Chris Hardy [MSFT] 2012-05-02 10:20:52 UTC
Whilst porting this application example: https://github.com/rciovati/Android-KeyboardView-Example

I get the following crash when I click a "Key".

I/dalvikvm-heap( 3314): Grow heap (frag case) to 9.737MB for 625936-byte allocation
I/MonoDroid( 3314): UNHANDLED EXCEPTION: System.NotSupportedException: Don't know how to convert type 'Android.Views.Keycode' to an Android.Runtime.IJavaObject.
I/MonoDroid( 3314): at Android.Runtime.JNIEnv.AssertIsJavaObject (System.Type) <0x000a4>
I/MonoDroid( 3314): at Android.Runtime.JNIEnv._GetArray (intptr,System.Type) <0x000c7>
I/MonoDroid( 3314): at Android.Runtime.JNIEnv.GetArray (intptr,Android.Runtime.JniHandleOwnership,System.Type) <0x00023>
I/MonoDroid( 3314): at Android.InputMethodServices.KeyboardView/IOnKeyboardActionListenerInvoker.n_OnKey_IarrayI (intptr,intptr,int,intptr) <0x00043>
I/MonoDroid( 3314): at (wrapper dynamic-method) object.c452b11d-2371-4a29-aac3-0b751894a837 (intptr,intptr,int,intptr) <0x0003b>
E/mono    ( 3314): 
E/mono    ( 3314): Unhandled Exception: System.NotSupportedException: Don't know how to convert type 'Android.Views.Keycode' to an Android.Runtime.IJavaObject.
E/mono    ( 3314):   at Android.Runtime.JNIEnv.AssertIsJavaObject (System.Type targetType) [0x00000] in <filename unknown>:0 
E/mono    ( 3314):   at Android.Runtime.JNIEnv._GetArray (IntPtr array_ptr, System.Type element_type) [0x00000] in <filename unknown>:0 
E/mono    ( 3314):   at Android.Runtime.JNIEnv.GetArray (IntPtr array_ptr, JniHandleOwnership transfer, System.Type element_type) [0x00000] in <filename unknown>:0 
E/mono    ( 3314):   at Android.InputMethodServices.KeyboardView+IOnKeyboardActionListenerInvoker.n_OnKey_IarrayI (IntPtr jnienv, IntPtr native__this, Int32 native_primaryCode, IntPtr native_keyCodes) [0x00000] in <filename unknown>:0 
E/mono    ( 3314):   at (wrapper dynamic-method) object:c452b11d-2371-4a29-aac3-0b751894a837 (intptr,intptr,int,intptr)


Which is coming from this code:

mKeyboardView.Key += (sender, e) => {
                long eventTime = JavaSystem.CurrentTimeMillis();
                KeyEvent ev = new KeyEvent(eventTime, eventTime, KeyEventActions.Down, e.PrimaryCode, 0, 0, 0, 0, KeyEventFlags.SoftKeyboard | KeyEventFlags.KeepTouchMode);
        
                this.DispatchKeyEvent(ev);
            };

Full project here: http://dl.dropbox.com/u/90453/CustomKeyboard.zip
Comment 1 Jonathan Pryor 2012-05-02 22:20:52 UTC
Fixed in 55c3b844.
Comment 2 Jonathan Pryor 2012-05-02 22:39:36 UTC
Also requires commit c55cea2d.