9

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.

3
  • Goto Settings > Applications and uninstall Xamarin and Mono runtimes from your device/virtual device. And try again. Commented Jan 21, 2017 at 19:31
  • @AkashKava Yeah, as I said in my post, that works and the application starts again, but it's a temporary fix and the problem always returns. Commented Jan 23, 2017 at 18:36
  • I noticed this error immediately after rooting the target samsung device (to install sqlite3 ARM binary). I also installed busybox (which doesn't have the only command needed, file, and won't uninstall cleanly). I advise not rooting a Samsung if meaningful testing is important. Commented Jul 10, 2017 at 20:46

4 Answers 4

7
+200

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I appreciate this solution. After beating my head up against the wall for quite awhile with this one, this solved my problem!
2

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.

Comments

0

Try removing all 'bin' and 'obj' folders in your project. Then clean and rebuild.

Comments

0

Had the same issue.

After working with Visual Studio + Xamarin, I must admit this environment is TERRIBLE. Issues arise not from your code, but from the complexity of the whole environment, and this also includes Google's requirements.

There are several things to check, including:

  • Cleansing AND creating the Build every single time you switch from debug, creating apk or creating aab files
  • removing bin and obj folders for EACH environment
  • check the options in the Android / iOS (depending with which you have issues) with the properties

There were several things involved, but one of them was using Proguard or R8, which caused crashing the app for no reason. Disabling those and leaving it empty allowed to deliver apk/aab file which didn't crash at startup.

It took me about ~10 hours to check everything.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.