Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms Android Application crashes on startup

When I launch a debug session for my Xamarin.Forms Android project, it crashes instantly, with the following error message:

java.lang.RuntimeException: Unable to get provider mono.MonoRuntimeProvider: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getAbsolutePath()' on a null object reference

I'm using Shared Runtime and Fast Deploy, although inactivating either doesn't seem to solve my problem.

What does solve my problem, however, is uninstalling the application manually from the device. Then it'll work for one debug session, but as soon as I start the next one, the same error is back.

It seems to me that the application is somehow unable to find the Mono Shared Runtime if it was installed in a previous debug session, but I can't for the life of me see why.

like image 946
Andreas Eriksson Avatar asked Jan 20 '17 20:01

Andreas Eriksson


2 Answers

Here are the steps to go through when trying to fix something like this:

  1. Are you using the latest stable version of Xamarin? If not, update.
  2. As mentioned in the comments, you should also try to remove the Mono runtime from your device. What you're looking for are the following items in the installed apps list (I'd only remove the Mono Shared Runtime first but it won't hurt to try to remove all of them):
    • Mono Shared Runtime
    • Mono Android-x Support
    • Xamarin.Android API-X Support
  3. Clean the solution and try again

If these don't fix the issue, you should post more from the error log. What I'm looking for is a few lines after the main exception definitions to see the stacktrace, like this (mainly the lines starting with at):

java.lang.RuntimeException: Unable to start activity ComponentInfo{plp.cs4b.thesis.drawitapp/plp.cs4b.thesis.drawitapp.PlayGame}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String plp.cs4b.thesis.drawitapp.Player.getName()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)

When working with Xamarin and Android, the error might not always be where the exception seems to be pointing at. That's why it's worth looking into it deeper in a situation like this.

like image 184
Timo Salomäki Avatar answered Oct 21 '22 09:10

Timo Salomäki


According to two other posts on SO found here:
Xamarin.Forms "App has stopped working" on android
Why does my Xamarin Android application suddenly require external storage permissions?
It looks like you "might" be missing the external storage permission, which usually is in the AssemblyInfo.cs file:
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)] Or you can set it in the AndroidManifest.xml file.
Or instead as the author of the first question posted his answer, he just changed the location of install to internal.
I suggest that this could be worth checking.

like image 2
Paul Karam Avatar answered Oct 21 '22 08:10

Paul Karam