简体   繁体   English

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

[英]Xamarin.Forms “App has stopped working” on android

So I encounterd this error just now and this causes my android application not to work on the device. 所以我刚刚遇到这个错误,这导致我的Android应用程序无法在设备上工作。 Whenever I debug my application for android it crashes for some reasont. 每当我为Android调试我的应用程序时,它会崩溃以获得一些权利。 . As a new user to Xamarin I'm clueless. 作为Xamarin的新用户,我很无能为力。

Here is the error I`m getting: 这是我得到的错误:

[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

I haven't really got something special in my project. 我的项目中没有特别的东西。 I can't upload a screenshot of my solution just yet but I`ll try and describe it: 我暂时无法上传我的解决方案的屏幕截图,但我会尝试描述它:

My solution exists out of SalesKicker and SalesKicker.Droid . 我的解决方案存在于SalesKickerSalesKicker.Droid之外 SalesKicker has 3 files MainPage.Xaml MainPage.Xaml.cs SalesKicker.cs . SalesKicker有3个文件MainPage.Xaml MainPage.Xaml.cs SalesKicker.cs and SalesKicker.Droid contains the usual stuff plus 1 image called delogo.png which I`m using as appicon. SalesKicker.Droid包含通常的东西加上1个名为delogo.png的图像,我用它作为appicon。 This is my MainActivity.cs code: 这是我的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 ());
    }
}

I've also been trying to set some breakpoints. 我也一直试图设置一些断点。 I've tried it on every line and still got the same error over and over again. 我已经尝试过每一行,但仍然一遍又一遍地得到同样的错误。 I also tried to set my "Target Version" to Lollipop 5.0, which is the current software version on my LG G3, and it didn't really have any effect. 我还尝试将我的“目标版本”设置为Lollipop 5.0,这是LG G3上的当前软件版本,并没有任何影响。 And I also have every single Android SDK installed. 我也安装了每一个Android SDK。 Since I'm quite new to Xamarin I'm clueless. 因为我对Xamarin很新,所以我很无能为力。 Can someone please tell me what I'm doing wrong here? 有人可以告诉我这里我做错了什么吗?

I got it after looking at another thread: Why does my Xamarin Android application suddenly require external storage permissions? 我看了另一个帖子后得到了它: 为什么我的Xamarin Android应用程序突然需要外部存储权限?

I just had to go to: AndroidManifest.xml and set 'Install location' to internalOnly . 我只需要去:AndroidManifest.xml并将'Install location'设置为internalOnly This worked for me. 这对我有用。

Create this folder on your android device if you can. 如果可以,请在Android设备上创建此文件夹。

/data/data/{your.apps.package.name}

Otherwise, uninstall your app then re-install it again. 否则,请卸载您的应用,然后重新安装。

You may noticed that the exception is rise by "File.getAbsolutePath()". 您可能会注意到“File.getAbsolutePath()”引发异常。

After decompile my app's .apk package, i found this is cause by getFilesDir() returning null . 反编译我的应用程序的.apk包后,我发现这是由getFilesDir()返回null引起的。

// MonoPackageManager.java
String str1 = context.getFilesDir().getAbsolutePath();  // <- Exception
String str2 = context.getCacheDir().getAbsolutePath();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM