如何修复“解析XML时出错:未关闭的令牌(APT0000)”? (Xamarin.Forms)

时间:2018-12-07 14:58:46

标签: c# xaml xamarin xamarin.forms xamarin.android

因此,我目前正在尝试弄清楚如何使用平台特定的代码。 iOS运行正常。但是Android让我遇到了麻烦,而且我不知道如何解决。

在iOS模拟器上运行相同的代码时,我的代码可以运行,但在Android模拟器上运行相同的代码,则出现错误“解析XML时出错:未关闭的令牌(APT0000)”。有谁知道为什么会发生以及如何解决这个问题?

xaml:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="BookCodeSL.PlatInfoSap1">


    <StackLayout Padding="20">
        <StackLayout VerticalOptions="CenterAndExpand">
            <Label Text="Device Model:"/>

            <ContentView Padding="50,0,0,0">
                <Label x:Name="modelLabel"
                       FontSize="Large"
                       FontAttributes="Bold"/>
            </ContentView>
        </StackLayout>

        <StackLayout VerticalOptions="CenterAndExpand">
            <Label Text="Operating System Version:"/>

            <ContentView Padding="50,0,0,0">
                <Label x:Name="versionLabel"
                       FontSize="Large"
                       FontAttributes="Bold"/>
            </ContentView>
        </StackLayout>
    </StackLayout>
</ContentPage>

cs:

//...
#elif __ANDROID__
using Android.OS;

//...

    public partial class PlatInfoSap1 : ContentPage
    {
        public PlatInfoSap1()
        {
            InitializeComponent();

#if __IOS__

            UIDevice device = new UIDevice();
            modelLabel.Text = device.Model.ToString();
            versionLabel.Text = String.Format("{0} {1}", device.SystemName, device.SystemVersion);

#elif __ANDROID__
            modelLabel.Text = String.Format("{0} {1}", Build.Manufacturer, Build.Model);


  versionLabel.Text = Build.VERSION.Release.ToString();

#endif
    }
}

编辑

该错误可以在

中找到

abc_primary_text_disable_only_material_light.xml

这是它的代码:

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND

2 个答案:

答案 0 :(得分:1)

您是否缺少abc_primary_text_disable_only_material_light.xml中的某些代码?

应该是:

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The Android Open Source Project
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
          http://www.apache.org/licenses/LICENSE-2.0
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:color="@color/bright_foreground_disabled_material_light"/>
    <item android:color="@color/bright_foreground_material_light"/>
</selector>

答案 1 :(得分:0)

您的XML似乎不是有效的XML。 请确保关闭所有XML属性,例如,在XML文件中最明显的

        // "filter": {
        //     ["==", "Severity", "2.0"],
        //     ["==", "Label Type", "Problem"]
        // }

https://www.xmlvalidation.com/