[mono-android] ClassNotFoundException with ItemClick event
Jonathan Pobst
monkey at jpobst.com
Fri Mar 25 10:43:35 EDT 2011
If you have linking on (Project Properties -> Mono for Android ->
Linking), try turning it off and see if it works.
Jonathan
On 3/25/2011 9:21 AM, Fabrice wrote:
>
>
> I've set up the log as requested:
>
> protected override void OnCreate(Bundle bundle)
>
> {
> base.OnCreate(bundle);
>
> //Set the Activity's view to our list layout
> SetContentView(Resource.Layout.DeviceList);
>
>
> var server =new MockServer();
> var listView =this.FindViewById<ListView>(Resource.Id.listView);
>
> listView.Adapter =new DeviceAdapter(this,Resource.Layout.OnOffDevice, server.GetDevices());
>
>
> //Wire up the click event
> try
> {
> listView.ItemClick +=new EventHandler<ItemEventArgs>(showToast);
>
> }
> catch (Java.Lang.Throwable e)
> {
> *Android.Util.Log.Error("no!", e,"this is the java-side exception.");*
>
> Toast.MakeText(this,"Error reported",ToastLength.Long).Show();
>
> }
> }
>
> Problem:
> Visual Studio correctly stop on the error when adding the handler. To be
> more detailed, it stop 2x:
>
> - Instance {Java.Lang.ClassNotFoundException: Exception of type
> 'Java.Lang.ClassNotFoundException' was thrown.
> at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr
> jmethod, Android.Runtime.JValue[] parms) [0x00024] in
> /home/jpobst/Desktop/mondroid/Mono.Android/src/Runtime/JNIEnv.cs:328
> at Android.Runtime.JNIEnv.FindClass (System.String classname)
> [0x00032] in
> /home/jpobst/Desktop/mondroid/Mono.Android/src/Runtime/JNIEnv.cs:155
> } Java.Lang.ClassNotFoundException
>
> - Instance {Java.Lang.NoClassDefFoundError: Exception of type
> 'Java.Lang.NoClassDefFoundError' was thrown.
> at Android.Runtime.JNIEnv.FindClass (System.String classname)
> [0x00066] in
> /home/jpobst/Desktop/mondroid/Mono.Android/src/Runtime/JNIEnv.cs:159
> at Android.Runtime.JNIEnv.FindClass (System.Type type) [0x00000] in
> /home/jpobst/Desktop/mondroid/Mono.Android/src/Runtime/JNIEnv.cs:126
> } Java.Lang.NoClassDefFoundError
>
> But I don't know why, it completely stop executing code: the catch is
> not executed (no log, no Toast)
> I also tested without the debugger (only on the device), same behaviour...
> I also tested using a "catch(Exception exc)" to be more generic, same
> behaviour: the catch code is not executed
>
> adb logcat (activity name is "HoMIDroid.DeviceActivity") doesn't show
> any error:
>
> I/monodroid(21979): Activating instance of type HoMIDroid.DeviceActivity
> I/monodroid(21979): signature
> D/dalvikvm(21465): GC_EXPLICIT freed 119 objects / 10144 bytes in 76m
> I/BatteryStatsImpl( 96): notePhoneSignalStrengthLocked: 3->4
> D/SurfaceFlinger( 96): Layer::requestBuffer(this=0x91c6d8), index=1,
> pid=21979, w=480, h=800 success
> D/SurfaceFlinger( 96): Layer::requestBuffer(this=0x91c6d8), index=0,
> pid=21979, w=480, h=800 success
> D/SurfaceFlinger( 96): Layer::requestBuffer(this=0x91c6d8), index=1,
> pid=21979, w=480, h=800 success
> D/dalvikvm(21473): GC_EXPLICIT freed 491 objects / 25424 bytes in 65ms
> D/PowerManagerService( 96): New lightsensor value:90, lcdValue:160
> D/PowerManagerService( 96): New lightsensor value:40, lcdValue:160
> W/KeyCharacterMap(21979): Bad keycharmap - filesize=32
> W/KeyCharacterMap(21979): Error loading keycharmap file
> '/system/usr/keychars/bravo-keypad.kcm.bin'.
> hw.keyboards.0.devname='bravo-keypad'
> W/KeyCharacterMap(21979): Using default keymap:
> /system/usr/keychars/qwerty.kcm.bin
> D/Sensors ( 96): close_akm, fd=170
> D/SurfaceFlinger( 96): Layer::setBuffers(this=0x9d0a88), pid=211,
> w=480, h=800
> D/SurfaceFlinger( 96): Layer::setBuffers(this=0x9d0a88), pid=211,
> w=480, h=800
> D/SurfaceFlinger( 96): Layer::requestBuffer(this=0x9d0a88), index=0,
> pid=211, w=480, h=800 success
> D/SurfaceFlinger( 96): Layer::requestBuffer(this=0x9d0a88), index=1,
> pid=211, w=480, h=800 success
> D/AK8973 ( 72): Compass CLOSE
> V/AlarmManager( 96): Adding Alarm{46982c80 type 0 com.htc.launcher}
> mars 26 12:00:00 matin
> D/PowerManagerService( 96): New lightsensor value:90, lcdValue:160
> I/BatteryStatsImpl( 96): notePhoneSignalStrengthLocked: 4->3
> I/BatteryStatsImpl( 96): notePhoneSignalStrengthLocked: 3->4
> D/dalvikvm(21481): GC_EXPLICIT freed 6522 objects / 356664 bytes in 94ms
>
>
>
> Thank you for your help
> Fabrice
>
>
>
> On Fri, Mar 25, 2011 at 2:27 PM, Jonathan Pryor <jpryor at novell.com
> <mailto:jpryor at novell.com>> wrote:
>
> On Mar 25, 2011, at 5:27 AM, Faze Faze wrote:
> > I'm new to monodroid (and new to android dev) and I'm facing a
> problem when binding the ItemClick event.
> ...
> >
> > protected override void OnCreate(Bundle bundle)
> > {
> ...
> > //Wire up the click event
> try {
> > listView.ItemClick += new
> EventHandler<ItemEventArgs>(showToast);
>
> } catch (Java.Lang.Throwable e) {
> Android.Util.Log.Error("no!", e, "this is the
> java-side exception.");
> }
>
> > Do you have any idea on where the problem is ?
>
> No, because we don't know what the Java-side message and stack trace
> are. (Fortunately, the next release will -- finally! -- include the
> Java side exception information when you call
> Java.Lang.Throwable.ToString()...)
>
> The above code wraps the call in a try/catch block, then uses
> Log.Error() to print the error message on the Android error log. You
> can then use `adb logcat` to view the Java-side exception message,
> which will either provide you enough information to figure out
> what's wrong, or provide us enough information to investigate
> further. :-)
>
> - Jon
>
> _______________________________________________
> Monodroid mailing list
> Monodroid at lists.ximian.com <mailto:Monodroid at lists.ximian.com>
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
>
>
>
>
> _______________________________________________
> Monodroid mailing list
> Monodroid at lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
More information about the Monodroid
mailing list