Как исправить ошибку «Ошибка синтаксического анализа XML: незащищенный токен (APT0000)»?(Xamarin.Forms) - PullRequest
0 голосов
/ 07 декабря 2018

Итак, я сейчас пытаюсь понять, как работать с кодом, специфичным для платформы.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
    }
}

edit

Ошибка может быть найдена в

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 голосов
/ 10 декабря 2018

Вам не хватает некоторых кодов в 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>
0 голосов
/ 07 декабря 2018

Кажется, ваш XML не является допустимым XML.Убедитесь, что вы закрыли каждое свойство XML, например, наиболее очевидное в вашем XML-файле:

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

. В этом вам может помочь https://www.xmlvalidation.com/

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...