You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET MAUI选项卡页面Android端异常及可用性咨询

.NET MAUI TabbedPage在Android平台的支持问题

问题详情

.NET MAUI中创建的TabbedPage在Windows平台运行正常,但在Android物理设备打开时抛出异常,相关代码及异常信息如下:

TabbedPage代码

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="MyApp.Pages.SomeClass"
    xmlns:Controls="clr-namespace:MyApp.Resources.Controls"
    xmlns:local="clr-namespace:MyApp.Pages"
    Title="Some title">
    <local:Page1 />
    <local:Page2 />
    <local:Page3 />
</TabbedPage>

子页面(以Page1为例)代码

XAML代码

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="MyApp.Pages.Page1"
    xmlns:Controls="clr-namespace:MyApp.Resources.Controls"
    xmlns:VerticalStackLayout="clr-namespace:MyApp.Resources.Controls"      
    Title="Vente">
    <VerticalStackLayout>
        <Label Text="Page 1"/>
    </VerticalStackLayout>
</ContentPage>

C#代码

public partial class Page1: ContentPage {
  public Page1() {
    InitializeComponent();
  }
}

Android平台抛出的异常

0xFFFFFFFFFFFFFFFF in Android.Runtime.JNIEnv.monodroid_debugger_unhandled_exception C#
0x1A in Android.Runtime.JNINativeWrapper._unhandled_exception at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:12,5 C#
0x23 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:353,26    C#
0xEE in Microsoft.Maui.Controls.Handlers.TabbedPageManager.SetTabLayout at D:\a\_work\1\s\src\Controls\src\Core\Platform\Android\TabbedPageManager.cs:240,5 C#
0x1BD in Microsoft.Maui.Controls.Handlers.TabbedPageManager.SetElement at D:\a\_work\1\s\src\Controls\src\Core\Platform\Android\TabbedPageManager.cs:162,5  C#
0x20 in Microsoft.Maui.Controls.TabbedPage.CreatePlatformView at D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\TabbedPage\TabbedPage.Android.cs:23,4 C#
0x10 in Microsoft.Maui.Controls.TabbedPage.OnCreatePlatformView at D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\TabbedPage\TabbedPage.Android.cs:30,5   C#
0x15 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.ITabbedView,Android.Views.View>.OnCreatePlatformView at D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:72,4 C#
0x1 in Microsoft.Maui.Handlers.ViewHandler.OnCreatePlatformElement at D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandler.cs:119,4    C#
0x1 in Microsoft.Maui.Handlers.ElementHandler.CreatePlatformElement at D:\a\_work\1\s\src\Core\src\Handlers\Element\ElementHandler.cs:96,4  C#
0x49 in Microsoft.Maui.Handlers.ElementHandler.SetVirtualView at D:\a\_work\1\s\src\Core\src\Handlers\Element\ElementHandler.cs:52,4    C#
0x2 in Microsoft.Maui.Handlers.ViewHandler.SetVirtualView at D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandler.cs:125,4 C#
0x2 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.ITabbedView,Android.Views.View>.SetVirtualView at D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:53,4    C#
0x7 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.ITabbedView,Android.Views.View>.SetVirtualView at D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:56,4    C#
0x65 in Microsoft.Maui.Controls.Element.SetHandler at D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\Element\Element.Impl.cs:64,6 C#
0x2 in Microsoft.Maui.Controls.Element.set_Handler at D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\Element\Element.Impl.cs:20,11    C#
0x18 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler at D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\VisualElement\VisualElement.Impl.cs:301,5 C#
0xB0 in Microsoft.Maui.Platform.ElementExtensions.ToHandler at D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:96,4   C#
0x2 in Microsoft.Maui.Platform.ViewExtensions.ToHandler at D:\a\_work\1\s\src\Core\src\Platform\ViewExtensions.cs:44,4  C#
0xAA in Microsoft.Maui.Controls.Platform.Compatibility.ShellContentFragment.OnCreateView at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellContentFragment.cs:145,4 C#
0x24 in AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_ at C:\a\_work\3\s\generated\androidx.fragment.fragment\obj\Release\net6.0-android\generated\src\AndroidX.Fragment.App.Fragment.cs:1999,4 C#
0xD in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:352,5  C#

核心疑问:.NET MAUI选项卡页面是否支持Android平台?


回答

.NET MAUI的TabbedPage完全支持Android平台,你遇到的异常并非平台不支持导致,而是代码中的命名冲突问题。

查看Page1的XAML代码,你引入了一个自定义命名空间:

xmlns:VerticalStackLayout="clr-namespace:MyApp.Resources.Controls"

这个命名空间名称和MAUI内置的VerticalStackLayout控件完全重名,Android平台的TabbedPage渲染逻辑在处理子页面时,会混淆自定义命名空间与内置控件,进而抛出异常。

解决步骤

  1. 移除这个多余的命名空间声明,或者将自定义命名空间重命名为不与MAUI内置控件冲突的名称,比如:
xmlns:CustomControls="clr-namespace:MyApp.Resources.Controls"
  1. 清理项目并重新构建,再部署到Android设备测试。

另外,建议使用稳定版MAUI SDK,避免因SDK版本Bug引发异常。


内容的提问来源于stack exchange,提问作者Thomas Carlton

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 10:41:17