Xamarin.Forms Droid Project: Debugger throws strange DivideByZero-Exception without further info.

AW.0337AW.0337 RUMember ✭✭

Hi all,

When I try to run my app on my Tablet after I logged in the debugger throws the following exception:


Unhandled Exception:

System.DivideByZeroException: Attempted to divide by zero.

06-01 09:58:36.073 D/Mono (13775): DllImport attempting to load: '/system/lib/liblog.so'.
06-01 09:58:36.075 D/Mono (13775): DllImport loaded library '/system/lib/liblog.so'.
06-01 09:58:36.075 D/Mono (13775): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so').
06-01 09:58:36.075 D/Mono (13775): Searching for '__android_log_print'.
06-01 09:58:36.075 D/Mono (13775): Probing '__android_log_print'.
06-01 09:58:36.075 D/Mono (13775): Found as '__android_log_print'.
06-01 09:58:36.092 I/MonoDroid(13775): UNHANDLED EXCEPTION:
06-01 09:58:36.101 I/MonoDroid(13775): System.DivideByZeroException: Attempted to divide by zero.
06-01 09:58:36.101 I/MonoDroid(13775): at (wrapper managed-to-native) System.Object:__icall_wrapper___emul_op_idiv (int,int)
06-01 09:58:36.101 I/MonoDroid(13775): at Xamarin.Forms.Platform.CarouselViewRenderer+VirtualLayoutManager.GetPosition (System.Int32 itemCount, System.Int32 positionOrigin, System.Int32 x, System.Boolean exclusive) [0x0000c] in <98ef4d3d8b214c838f1b190032afb88a>:0
06-01 09:58:36.101 I/MonoDroid(13775): at Xamarin.Forms.Platform.CarouselViewRenderer+VirtualLayoutManager.GetPositions (System.Int32 positionOrigin, System.Int32 itemCount, System.Drawing.Rectangle viewport) [0x0000e] in <98ef4d3d8b214c838f1b190032afb88a>:0
06-01 09:58:36.101 I/MonoDroid(13775): at Xamarin.Forms.Platform.PhysicalLayoutManager.OnLayoutChildren (Android.Support.V7.Widget.RecyclerView+Recycler recycler, Android.Support.V7.Widget.RecyclerView+State state) [0x00053] in <98ef4d3d8b214c838f1b190032afb88a>:0
06-01 09:58:36.102 I/MonoDroid(13775): at Android.Support.V7.Widget.RecyclerView+LayoutManager.n_OnLayoutChildren_Landroid_support_v7_widget_RecyclerView_Recycler_Landroid_support_v7_widget_RecyclerView_State_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_recycler, System.IntPtr native_state) [0x00019] in <00ef854e109241db9d853f1dd4d69cd9>:0
06-01 09:58:38.224 W/art (13775): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
06-01 09:58:38.231 D/Mono (13775): DllImport searching in: '__Internal' ('(null)').
06-01 09:58:38.231 D/Mono (13775): Searching for 'java_interop_jnienv_throw'.
06-01 09:58:38.231 D/Mono (13775): Probing 'java_interop_jnienv_throw'.
06-01 09:58:38.231 D/Mono (13775): Found as 'java_interop_jnienv_throw'.


Unhandled Exception:

System.DivideByZeroException: Attempted to divide by zero.

06-01 09:58:40.559 I/MonoDroid(13775): UNHANDLED EXCEPTION:
06-01 09:58:40.575 I/MonoDroid(13775): System.DivideByZeroException: Attempted to divide by zero.
06-01 09:58:40.575 I/MonoDroid(13775): at (wrapper managed-to-native) Java.Interop.NativeMethods:java_interop_jnienv_call_nonvirtual_void_method_a (intptr,intptr&,intptr,intptr,intptr,Java.Interop.JniArgumentValue)
06-01 09:58:40.575 I/MonoDroid(13775): at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue
args) [0x00073] in :0
06-01 09:58:40.575 I/MonoDroid(13775): at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0001f] in :0
06-01 09:58:40.575 I/MonoDroid(13775): at Android.Views.ViewGroup.Layout (System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x00062] in <98faa656946244a1834d2a7d7d7a8c19>:0
06-01 09:58:40.575 I/MonoDroid(13775): at Xamarin.Forms.Platform.Android.ViewRenderer`2[TView,TNativeView].OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x00059] in <1481f85a917c4f2b882ea161e9bc082f>:0
06-01 09:58:40.575 I/MonoDroid(13775): at Xamarin.Forms.Platform.CarouselViewRenderer.OnLayout (System.Boolean changed, System.Int32 left, System.Int32 top, System.Int32 right, System.Int32 bottom) [0x00017] in <98ef4d3d8b214c838f1b190032afb88a>:0
06-01 09:58:40.575 I/MonoDroid(13775): at Xamarin.Forms.Platform.Android.FormsViewGroup.n_OnLayout_ZIIII (System.IntPtr jnienv, System.IntPtr native__this, System.Boolean p0, System.Int32 p1, System.Int32 p2, System.Int32 p3, System.Int32 p4) [0x00008] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android.FormsViewGroup\obj\Release\generated\src\Xamarin.Forms.Platform.Android.FormsViewGroup.cs:198
06-01 09:58:40.576 I/MonoDroid(13775): at (wrapper dynamic-method) System.Object:bc77244e-5169-4d92-9b5b-a03879b87915 (intptr,intptr,bool,int,int,int,int)
Thread finished: #9
06-01 09:58:50.211 D/Mono (13775): [0x5ec81920] worker finishing
The thread 'Unknown' (0x9) has exited with code 0 (0x0).


On Windows everything runs without any error.

I got the the StackTraces after adding custom ExceptionHandlers to the MainActivity.cs in the Droid-project but nonetheless I don't know where to dig to get to the problem.

How can I get more information out of VS2015 and the debugger to find and solve this problem?

Further env. Infos for You:

  • VS Professional 2015 Version 14.0.25431.01 Update 3
  • Xamarin.Forms v2.3.4.247 in all projects
  • Xamrin.Forms.CarouselView v2.3.0-pre2 in all App-projects
  • all Xamarin.Android.Support-Packages are v23.3.0
  • Sqlite-net-pcl v 1.3.3 + dependencies

My test-device is an Nexus 7 Tablet with Android 7.1 (LineageOS)
The app itself is compatible with Android 6 upwards.

Best Answer

  • AW.0337AW.0337 RU ✭✭
    Accepted Answer

    Ah, sorry. Unfortunately I mixed both up...

    After being two weeks off (vacation), I'll give it a try with Your CarouselView.

    Hope, I'll get things running ;)

    So this thread can be closed.

    Thank You all for Your engagement!

    Regards
    Alex

Answers

  • VenkataSwamyVenkataSwamy INMember ✭✭✭
    edited June 2017

    Hii @AW.0337

    Might be your code is wrong please see below link

    https://developer.xamarin.com/api/type/System.DivideByZeroException/

    Might be your putting these condition

      if(Xamarin.Forms.Device.Idiom == TargetIdiom.Tablet)
         {               
              int x = 0;
              try { 
                          int y = 100/x;
                    }
               catch (DivideByZeroException ex) 
                   {
                           var msg=ex.Message;
                   }
          }      
    
  • AW.0337AW.0337 RUMember ✭✭
    edited June 2017

    Hi VenkataSwamyBalaraju,

    thank You very much for Your suggestion, but as I wrote above:

    On Windows everything runs without any error.

    Such a syntax- or arithmetic thing would throw an exception in windows too.

    BTW:

    I catch my exceptions with the following Code in my MainActivity.cs (droid-proj.):

    private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs) {
                if (unhandledExceptionEventArgs.ExceptionObject != null) {
                    System.Diagnostics.Debugger.Break();
                }
            }
    
        private static void AndroidEnvironmentOnUnhandledExceptionRaiser(object sender, RaiseThrowableEventArgs raiseThrowableEventArgs) {
            if (raiseThrowableEventArgs.Exception != null) {
                System.Diagnostics.Debugger.Break();
            }
        }
    

    and added these two lines in my OnCreate-Method:

    AndroidEnvironment.UnhandledExceptionRaiser += AndroidEnvironmentOnUnhandledExceptionRaiser;
    AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
    

    Every exception runs into this both methods but the stacktraces above are absolutely meaningless to me :/

    I suspect there's something wrong with Androids CarouselView renderer but don't know how to find and solve this.
    Best Regards

  • AW.0337AW.0337 RUMember ✭✭

    Just for documentation-purposes...

    This bug report seems to show the same problem I ran into:

    https://bugzilla.xamarin.com/show_bug.cgi?id=53382

  • AW.0337AW.0337 RUMember ✭✭

    @alexrainman

    Hello Alex,

    Have You, as the father of the CarouselView, seen such a behavior like the one I described above?

    I'm stuck since the beginning of the week at this point and don't know how to solve or better, where I have to search for the causality.

    I wrote above:

    I suspect there's something wrong with Androids CarouselView renderer but don't know how to find and solve this.

    But - to be honest - I think that I've overseen something or use incompatible libs or code.

    Thank you in advance and best regards
    Alex W.

  • alexrainmanalexrainman USMember ✭✭

    @AW.0337 that's not my CarouselView :wink:

  • AW.0337AW.0337 RUMember ✭✭

    @alexrainman said:
    @AW.0337 that's not my CarouselView :wink:

    Sorry, I thought You were the main-dev... :hushed:
    -> https://github.com/alexrainman/CarouselView

    Regards

  • alexrainmanalexrainman USMember ✭✭

    @AW.0337 that one yes but not Xamarin.Forms.CarouselView v2.3.0-pre2 :)

  • AW.0337AW.0337 RUMember ✭✭

    Ah, sorry. Unfortunately I mixed both up...

    After being two weeks off for vacation, I'll give it a try with Your CarouselView.

    Hope, I'll get things running ;)

  • AW.0337AW.0337 RUMember ✭✭
    Accepted Answer

    Ah, sorry. Unfortunately I mixed both up...

    After being two weeks off (vacation), I'll give it a try with Your CarouselView.

    Hope, I'll get things running ;)

    So this thread can be closed.

    Thank You all for Your engagement!

    Regards
    Alex

Sign In or Register to comment.