Итак, я сейчас пытаюсь понять, как работать с кодом конкретной платформы. 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
@GeraldVersluis тег </ContentPage> включен в вопрос, но не виден из-за неправильного форматирования кода. Он появляется при нажатии на кнопку edit.
Эта ошибка появляется, если ваши xml-теги закрыты неправильно.
Конечный тег не отсутствует в моем коде. pfx прав. Здесь я не смог отформатировать код. Прости





Похоже, ваш XML не является допустимым XML. Убедитесь, что вы закрыли все свойства XML, например, наиболее очевидное в вашем XML-файле
<ContentPage ...>
...
</ContentPage>
Это может вам в этом помочь, https://www.xmlvalidation.com/
Конечный тег включен в мой xaml. Он просто не появился здесь в stackoverflow из-за того, что я не смог правильно отформатировать свой код. Прости.
Вам не хватает кодов в 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>
Привет. Я только что пробовал это. Это все еще не работает. Та же ошибка :(
@axbeit Ошибка только в abc_primary_text_disable_only_material_light.xml? Есть ли другой XML-файл, в котором возникает такая же ошибка? Попробуйте удалить папку .bin и .obj в вашем проекте Android, а затем очистите и перестройте свой проект.
Завершен ли XAML для вашей страницы? Если да, то вам не хватает закрывающего тега
</ContentPage>.