c# – Xamarin.Forms“App已停止工作”在android上

所以我刚刚遇到这个错误,这导致我的
Android应用程序无法在设备上工作.每当我为Android调试我的应用程序时,它会崩溃以获得一些权利. .作为Xamarin的新用户,我很无能为力.

这是我得到的错误:

[art] Late-enabling -Xcheck:jni
[ContextImpl] Unable to create files subdir /data/data/com.comhuis.saleskicker.sales_kicker/cache
[ContextImpl] Unable to create files subdir /data/data/com.comhuis.saleskicker.sales_kicker/files
[AndroidRuntime] Shutting down VM
[AndroidRuntime] FATAL EXCEPTION: main
[AndroidRuntime] Process: com.comhuis.saleskicker.sales_kicker, PID: 5035
[AndroidRuntime] 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
[AndroidRuntime]    at android.app.ActivityThread.installProvider(ActivityThread.java:5015)
[AndroidRuntime]    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4607)
[AndroidRuntime]    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4547)
[AndroidRuntime]    at android.app.ActivityThread.access$1500(ActivityThread.java:148)
[AndroidRuntime]    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
[AndroidRuntime]    at android.os.Handler.dispatchMessage(Handler.java:102)
[AndroidRuntime]    at android.os.Looper.loop(Looper.java:135)
[AndroidRuntime]    at android.app.ActivityThread.main(ActivityThread.java:5272)
[AndroidRuntime]    at java.lang.reflect.Method.invoke(Native Method)
[AndroidRuntime]    at java.lang.reflect.Method.invoke(Method.java:372)
[AndroidRuntime]    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)
[AndroidRuntime]    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)
[AndroidRuntime] Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getAbsolutePath()' on a null object reference
[AndroidRuntime]    at mono.MonoPackageManager.LoadApplication(MonoPackageManager.java:27)
[AndroidRuntime]    at mono.MonoRuntimeProvider.attachInfo(MonoRuntimeProvider.java:42)
[AndroidRuntime]    at android.app.ActivityThread.installProvider(ActivityThread.java:5012)
[AndroidRuntime]    ... 11 more
[Process] Sending signal. PID: 5035 SIG: 9

我的项目中没有特别的东西.我暂时无法上传我的解决方案的屏幕截图,但我会尝试描述它:

我的解决方案存在于SalesKicker和SalesKicker.Droid之外. SalesKicker有3个文件MainPage.Xaml MainPage.Xaml.cs SalesKicker.cs.
和SalesKicker.Droid包含通常的东西加上1个名为delogo.png的图像,我用它作为appicon.这是我的MainActivity.cs代码:

namespace SalesKicker.Droid
{
    [Activity (Label = @"Sales Kicker", Icon = "@drawable/delogo", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity :     global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
    {
    protected override void OnCreate (Bundle bundle)
    {
        Xamarin.Insights.Initialize (global::SalesKicker.Droid.XamarinInsights.ApiKey, this);
        base.OnCreate (bundle);
        global::Xamarin.Forms.Forms.Init (this, bundle);
        LoadApplication (new App ());
    }
}

我也一直试图设置一些断点.我已经尝试过每一行,但仍然一遍又一遍地得到同样的错误.我还尝试将我的“目标版本”设置为Lollipop 5.0,这是LG G3上的当前软件版本,并没有任何影响.我也安装了每一个Android SDK.因为我对Xamarin很新,所以我很无能为力.有人可以告诉我这里我做错了什么吗?

最佳答案 看完另一个帖子后我得到了它:
Why does my Xamarin Android application suddenly require external storage permissions?

我只需要去:AndroidManifest.xml并将’Install location’设置为internalOnly.这对我有用.

点赞