我刚遇到了这个错误,导致我的安卓应用在设备上无法运行。每当我为安卓调试应用程序时,出现崩溃的情况。作为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 有三个文件 MainPage.Xaml MainPage.Xaml.cs SalesKicker.cs。 而 SalesKicker.Droid 包含通常的东西,以及一个名为 delogo.png 的图像,我将其用作应用程序图标。这是我的 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的新手,我感到很茫然。请问有人能告诉我我做错了什么吗?