Xamarin.Forms“应用程序已停止工作"在安卓上 [英] Xamarin.Forms "App has stopped working" on android

查看:37
本文介绍了Xamarin.Forms“应用程序已停止工作"在安卓上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我刚才遇到了这个错误,这导致我的 android 应用程序无法在设备上运行.每当我为 android 调试我的应用程序时,它都会出于某种原因崩溃..作为 Xamarin 的新用户,我一无所知.

So I encounterd this error just now and this causes my android application not to work on the device. Whenever I debug my application for android it crashes for some reasont. . As a new user to Xamarin I'm clueless.

这是我得到的错误:

[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:

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

My solution exists out of SalesKicker and SalesKicker.Droid. SalesKicker has 3 files 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. This is my MainActivity.cs code:

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 很陌生,因此我一无所知.有人可以告诉我我在这里做错了什么吗?

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. And I also have every single Android SDK installed. Since I'm quite new to Xamarin I'm clueless. Can someone please tell me what I'm doing wrong here?

推荐答案

我看了另一个帖子后明白了:为什么我的 Xamarin Android 应用程序突然需要外部存储权限?

I got it after looking at another thread: Why does my Xamarin Android application suddenly require external storage permissions?

我只需转到:AndroidManifest.xml 并将安装位置"设置为 internalOnly.这对我有用.

I just had to go to: AndroidManifest.xml and set 'Install location' to internalOnly. This worked for me.

这篇关于Xamarin.Forms“应用程序已停止工作"在安卓上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆