简体   繁体   English

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

[英]How do I fix “Error parsing XML: unclosed token (APT0000)” ? (Xamarin.Forms)

So Im currently trying to figure out how to work with platform specific code. 因此,Im目前正在尝试弄清楚如何使用平台特定的代码。 iOS works just fine. iOS运行正常。 But Android is making me problems and I dont know how to fix it. 但是Android让我遇到了麻烦,而且我不知道如何解决。

When running the same code on an iOS emulator my code works but running the same code on an Android Emulator it gives me the error "Error parsing XML: unclosed token (APT0000)". 在iOS模拟器上运行相同的代码时,我的代码可以运行,但在Android模拟器上运行相同的代码,则出现错误“解析XML时出错:未关闭的令牌(APT0000)”。 Does anyone know why it happens and how to fix this? 有谁知道为什么会发生以及如何解决这个问题?

xaml: 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: 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
    }
}

edit 编辑

The error can be found in 错误可以在

abc_primary_text_disable_only_material_light.xml abc_primary_text_disable_only_material_light.xml

this is the code to it: 这是它的代码:

<?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

Are you missing some codes in the abc_primary_text_disable_only_material_light.xml ? 您是否在abc_primary_text_disable_only_material_light.xml缺少一些代码?

It should be: 它应该是:

<?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>

It seems that your XML is not a valid XML. 您的XML似乎不是有效的XML。 Please make sure that you close every XML property, for example, the most obvious in your XML file the 请确保关闭所有XML属性,例如,在XML文件中最明显的

<ContentPage ...>
...
</ContentPage>

This can help you with that, https://www.xmlvalidation.com/ 这可以为您提供帮助, https://www.xmlvalidation.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM