Unable to get Raygun running in Xamarin Android App.
MarkLFT
Posted on
Mar 28 2014
I have an Android App created using Xamarin. Using NuGet I added the RayGun libaray to my project. The added RaygunClient.Attach("actualkeyused"); into the OnCreate method of the initial Activity called.
The app builds correctly, but whenever I run the app on a device I receive a Java.Lang.NullPointerException thrown. The call stack indicates this error as follows:
0x11 in Mindscape.Raygun4Net.RaygunClient.get_HasInternetConnection at e:\Users\Jason\Documents\GitHub\raygun4net\Mindscape.Raygun4Net.Xamarin.Android\RaygunClient.cs:336 0x1 in Mindscape.Raygun4Net.RaygunClient.SendStoredMessages at e:\Users\Jason\Documents\GitHub\raygun4net\Mindscape.Raygun4Net.Xamarin.Android\RaygunClient.cs:403 C#
0x1 in Mindscape.Raygun4Net.RaygunClient.<.ctor>b__0 at e:\Users\Jason\Documents\GitHub\raygun4net\Mindscape.Raygun4Net.Xamarin.Android\RaygunClient.cs:41 C#
Which leads me to one of three conclusions, I have put this call in completely the wrong place, or I have missed a vital step in implementing RayGun, or three, there is a bug in RayGun. I am tending towards one or two at this stage. But any help would be greatly appreciated.
Thanks
John-Daniel Trask
Raygun
Posted on
Mar 31 2014
Hi Mark,
I've given the package a run-through and it appears to be working on both the emulator and a physical device (Galaxy Tab, Jellybean), but that doesn't necessarily rule out a bug in the provider.
Do you also see this NPE when running on an emulator?
One thing I notice is that the line numbers aren't quite matching up there. Can you confirm that this behaviour is present with the latest 2.0.1 from the Xamarin Component Store at https://components.xamarin.com/view/raygun4net - also that normal internet connectivity is available from the device. I will keep investigating this one in the meantime.
Regards,
Callum Gavin
Mindscape Limited
MarkLFT
Posted on
May 16 2014
My apologies for not replying sooner to this message, I have been somewhat distracted with a month in hospital and the passing of my Mother.
The version I use within my app I download form NuGet, which I would presume is the latest version?
I have updated the NuGet verison, and below is the error I receive. Also below is the code I use for testing. This error is thrown on the Send line. This is from the first Activity that is loaded when the app starts.
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
RaygunClient.Attach("KEY");
RaygunClient.Current.ApplicationVersion = "1.1";
RaygunClient.Current.Send(new System.Exception("Test Error"));
.... Lots of other code
}
Java.Lang.NullPointerException: 05-16 17:50:37.790 W/Mono (24986): The request to load the assembly System v2.0.5.0 was remapped to v2.0.0.0 05-16 17:50:37.790 D/Mono (24986): Unloading image System.dll [0x5598d498]. 05-16 17:50:37.790 D/Mono (24986): Image addref System[0x5598d100] -> System.dll[0x55269fe0]: 4 05-16 17:50:37.790 D/Mono (24986): Assembly Ref addref Mindscape.Raygun4Net.Xamarin.Android[0x5501ffb8] -> System[0x553576d8]: 3 An unhandled exception occured. 05-16 17:50:39.705 I/MonoDroid(24986): UNHANDLED EXCEPTION: Java.Lang.NullPointerException: Exception of type 'Java.Lang.NullPointerException' was thrown. 05-16 17:50:39.705 I/MonoDroid(24986): at Android.Runtime.JNIEnv.CallNonvirtualObjectMethod (intptr,intptr,intptr,Android.Runtime.JValue[])
Java.Lang.NullPointerException: Loading... 05-16 17:50:39.830 I/dalvikvm(24986): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238) 05-16 17:50:39.830 I/dalvikvm(24986): at android.os.Handler.dispatchMessage(Handler.java:99) 05-16 17:50:39.830 I/dalvikvm(24986): at android.os.Looper.loop(Looper.java:137) 05-16 17:50:39.830 I/dalvikvm(24986): at android.app.ActivityThread.main(ActivityThread.java:4947) 05-16 17:50:39.830 I/dalvikvm(24986): at java.lang.reflect.Method.invokeNative(Native Method) 05-16 17:50:39.830 I/dalvikvm(24986): at java.lang.reflect.Method.invoke(Method.java:511) The program 'Mono' has exited with code 0 (0x0).
Many thanks
Mark
Jason Fauchelle
Raygun
Posted on
May 20 2014
No worries Mark, thanks for providing this additional information.
You're code looks perfectly fine, and it sounds like you have the latest version. I've tried your code out on an emulator and a device which both successfully sent an exception to Raygun.
My best guess is that sending the exception in the OnCreate method is too early. Raygun makes a call to Context.GetSystemService to determine if an internet connection is available before sending. It turns out that this call can throw a NullPointerException if it is called before Android is ready. It may be that this only occurs in certain Android versions which could explain why I haven't reproduced it.
What I would recommend is that you test sending an exception after the application has fully initialized. i.e as a result of pressing a button, rather than in the OnCreate method.
Thanks again for posting, this will help us improve the setup and initial testing process. Unfortunately it won't be as simple as putting a try catch block around the offending code, as that will fail the internet connection test and not send the exception which is also a bad first experience, but we'll think of something.
Let me know if you have further questions.
-Jason Fauchelle