android - 启动时 Xamarin Android.FormsAppCompatActivity NullReferenceException

标签 android xamarin prism nullreferenceexception

我尽可能地精简了我的应用程序以找到这个问题。仍然显示:

11-12 15:56:27.908 I/MonoDroid(17629): System.NullReferenceException: Object reference not set to an instance of an object.
11-12 15:56:27.908 I/MonoDroid(17629):   at Xamarin.Forms.Platform.Android.AppCompat.Platform.LayoutRootPage (Xamarin.Forms.Page page, System.Int32 width, System.Int32 height) [0x0005d] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:279 
11-12 15:56:27.908 I/MonoDroid(17629):   at Xamarin.Forms.Platform.Android.AppCompat.Platform.Xamarin.Forms.Platform.Android.IPlatformLayout.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x00003] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:196 
11-12 15:56:27.908 I/MonoDroid(17629):   at Xamarin.Forms.Platform.Android.PlatformRenderer.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x0000e] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\PlatformRenderer.cs:73 
11-12 15:56:27.908 I/MonoDroid(17629):   at Android.Views.ViewGroup.n_OnLayout_ZIIII (System.IntPtr jnienv, System.IntPtr native__this, System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x00009] in /Users/builder/data/lanes/3511/ce955cc0/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.ViewGroup.cs:3427 
11-12 15:56:27.908 I/MonoDroid(17629):   at (wrapper dynamic-method) System.Object:784a0fc1-dc7c-42ec-831f-0701fd382e8e (intptr,intptr,bool,int,int,int,int)
11-12 15:56:27.925 W/art     (17629): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable

这是我的 Android Activity

[Activity(Label = "Bol",Icon = "@drawable/icon",MainLauncher = true,Theme = "@style/MyTheme.Splash", NoHistory = true)]
public class MainActivity : FormsAppCompatActivity

对于启动画面,我有以下值/styles.xml

<resources>
 <style name="MyTheme.Splash" parent ="Theme.AppCompat.Light.NoActionBar">
  <item name="android:windowBackground">@drawable/splash_screen</item>
  <item name="android:windowNoTitle">true</item>
  <item name="android:windowActionBar">false</item>
  <item name="android:windowFullscreen">true</item>
  <item name="android:actionBarSize">0dp</item>
 </style>
</resources>

还有drawable/splash_screen.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="#000000"/>
</item>
<item>
<bitmap
    android:src="@drawable/icon"
    android:tileMode="disabled"
    android:gravity="center"/>
</item>
</layer-list>

和 Xamarin (Prism) 应用程序

public class App : PrismApplication
{
    public App(IPlatformInitializer initializer = null) : base(initializer) { }

    protected override void OnInitialized()
    {
        Logger = Container.Resolve(typeof(ILogger), null, new CompositeResolverOverride()) as ILoggerFacade;
        var navigationPage = "NavigationPage/MainMenu";
        NavigationService.NavigateAsync(navigationPage);
    }
}

MainMenu 只是一个空的 ContentPage。

我没有看到任何关于在 Xamarin.Forms.Platform.Android.AppCompat.Platform.LayoutRootPage 期间导致 NullReference 的提示

最佳答案

OnInitialized 标记为 asyncawait NavigationService.NavigateAsync(navigationPage);。那应该可以解决您的问题。

关于android - 启动时 Xamarin Android.FormsAppCompatActivity NullReferenceException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40566601/

相关文章:

c# - Prism 应用程序中的奇怪异常

wpf - Prism - 如何使用 MEF 在 ViewModel 中导入 IRegionManager

c# - 使用 XAML 进行依赖注入(inject),这可能吗?

Java SAX 解析器和多个 ContentHandler

android - Android Market 许可证服务器的 LICENSED 响应的典型 VT 值是多少?

android - 如何从音频剪辑转换文本?

android - Xamarin android 应用程序在某些设备上的 https 调用失败

xamarin - 如何在 Xamarin.Forms 上使用 Android AutoCompleteTextView

c# - Xamarin 添加 System.Json

Android 市场上市名称