Xamarin.Formsフレームワークを使用してクロスプラットフォームアプリケーションを構築しようとしています。私は自分のアプリにダミーのRestful APIを表示しようとしていますが、次のページを起動するとアプリケーションがクラッシュしています。手伝っていただけませんか?私がこれを理解することができれば、これは大きなステップになります。ありがとうございました!Xamarin.Forms:快適なAPIを実装しようとしましたが、アプリケーションがクラッシュし続けます
これが私の見解ページです: ApiPage.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="MyApp.Views.ApiPage">
<StackLayout>
<StackLayout Orientation="Horizontal">
</StackLayout>
<ListView x:Name="postsListView">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Title}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
これは、背後にあるコードです:これは、コンソール出力である ApiPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace MyApp.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public class Post
{
public int Id { get; set; }
public string Title { get; set; }
public string Body { get; set; }
}
public partial class ApiPage : ContentPage
{
private const string Url = "https://jsonplaceholder.typicode.com/posts";
private HttpClient _client = new HttpClient();
private ObservableCollection<Post> _posts;
public ApiPage()
{
InitializeComponent();
}
protected override async void OnAppearing()
{
var content = await _client.GetStringAsync(Url);
var posts = JsonConvert.DeserializeObject<List<Post>>(content);
_posts = new ObservableCollection<Post>(posts);
postsListView.ItemsSource = _posts;
base.OnAppearing();
}
void OnAdd(object sender, System.EventArgs e)
{
}
void OnUpdate(object sender, System.EventArgs e)
{
}
void OnDelete(object sender, System.EventArgs e)
{
}
}
}
が、何も言わない:
11-04 18:12:09.430 D/Mono (4185): Probing 'java_interop_jnienv_call_boolean_method'.
11-04 18:12:09.431 D/Mono (4185): Found as 'java_interop_jnienv_call_boolean_method'.
11-04 18:12:09.521 W/art (4185): JNI RegisterNativeMethods: attempt to register 0 native methods for md5b60ffeb829f638581ab2bb9b1a7f4f3f.CellRenderer_RendererHolder
11-04 18:12:12.450 D/Mono (4185): Assembly Ref addref MyApp[0x9e1a6480] -> Newtonsoft.Json[0xb030b7c0]: 2
11-04 18:12:12.576 D/Mono (4185): Assembly Ref addref Mono.Security[0xad5563a0] -> System[0x9e1a78c0]: 14
An unhandled exception occured.
ありがとうございます!!!!!あなたは私の命を救いました!!! – eccoripo