質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Windows 10

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

Xamarin

Xamarin(ザマリン)は、iPhoneなどのiOSやAndroidで動作し、C# 言語を用いてアプリを開発できるクロスプラットフォーム開発環境です。Xamarin Studioと C# 言語を用いて、 iOS と Android の両方の開発を行うことができます。

Q&A

解決済

1回答

2035閲覧

Cannot convert "2017/08/●" into Xamarin.Forms.Colorエラーでデバッグ実行できず

super1234

総合スコア52

Windows 10

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

Xamarin

Xamarin(ザマリン)は、iPhoneなどのiOSやAndroidで動作し、C# 言語を用いてアプリを開発できるクロスプラットフォーム開発環境です。Xamarin Studioと C# 言語を用いて、 iOS と Android の両方の開発を行うことができます。

0グッド

0クリップ

投稿2017/08/25 06:45

編集2017/08/27 14:02

xamarin.formsプログラムについて質問です。

環境はwin10 visual studio2017
データベース接続するInterfaceとDBアクションと項目名のgetsetを作成してPCL化し、
SampleApp.csから参照している状態です。
(参考:Xamarin エキスパート養成読本)

下記エラーが出ています。

ーーーーーーーーーーーーーーーーーーーー
Unhandled Exception:

System.InvalidOperationException: Cannot convert "2017/08/●● ●●:●●" into Xamarin.Forms.Color

このデバッグが止まっている箇所はMainActivity.csの23行目LoadApplicationになります。詳細は下記です。

ーーーーーーーーーーーーーーーーーーーー
イメージ説明

ーーーーーーーーーーーーーーーーーーーー
デバッグ中の出力は以下です。
ーーーーーーーーーーーーーーーーーー
08-25 15:03:04.285 D/Mono (32120): Image addref System.Runtime.Serialization[0x9c94b040] -> System.Runtime.Serialization.dll[0x9c92d600]: 2
08-25 15:03:04.285 D/Mono (32120): Prepared to set up assembly 'System.Runtime.Serialization' (System.Runtime.Serialization.dll)
08-25 15:03:04.286 D/Mono (32120): Assembly System.Runtime.Serialization[0x9c94b040] added to domain RootDomain, ref_count=1
08-25 15:03:04.289 D/Mono (32120): AOT: image 'System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app/SampleApp.Android-1/lib/arm/libaot-System.Runtime.Serialization.dll.so" not found
08-25 15:03:04.291 D/Mono (32120): AOT: image '/usr/local/lib/mono/aot-cache/arm/System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app/SampleApp.Android-1/lib/arm/libaot-System.Runtime.Serialization.dll.so" not found
08-25 15:03:04.291 D/Mono (32120): Config attempting to parse: 'System.Runtime.Serialization.dll.config'.
08-25 15:03:04.291 D/Mono (32120): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Runtime.Serialization/System.Runtime.Serialization.config'.
08-25 15:03:04.291 D/Mono (32120): Assembly Ref addref Mono.Android[0xaf37be80] -> System.Runtime.Serialization[0x9c94b040]: 2
08-25 15:03:04.294 D/Mono (32120): Assembly Ref addref System.Runtime.Serialization[0x9c94b040] -> mscorlib[0xaf37b4c0]: 37
ーーーーーーーーーーーーーーーーーー

ハンドルされていないエラーとしてデバッグを始めた直後にデバッグが止まってしまい、
googleなどで調べても解決できない状態です。書籍問い合わせもしていますが、いっこうにお返事なく
何かアドバイス頂けないでしょうか。
よろしくお願いいたします。

ご指摘アドバイス頂きましてPCL側なども記載します。

●全体的な構成

下記のようにPCLプロジェクトを作成
![イイメージ説明(f4755f61160ee8cac59a3204fcf6cd25.png)

そのPCLを参照しているSampleAppプロジェクトを作成
イメージ説明

●主要なコード

PCL側
・SamplePCL.cs

namespace SamplePCL
{
public class SamplePCL : ContentPage
{
public SamplePCL()
{
var button = new Button
{
Text = "Click Me!",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
};

int clicked = 0; button.Clicked += (s, e) => button.Text = "Clicked: " + clicked++; Content = button; } }

}

・SqliteControl.cs

using System.Collections.Generic;
using SQLite.Net;
using Xamarin.Forms;

namespace SampleApp
{
public class SqliteControl
{
static readonly object wObject = new object();
readonly SQLiteConnection wSQLiteConnection;
// SQLiteデータベースに接続
public SqliteControl()
{
//接続
wSQLiteConnection =
DependencyService.Get<ISqliteInterface>().GetConnection();
// データ管理用テーブル作成
wSQLiteConnection.CreateTable<SqliteItem>();

} // データの取得 public IEnumerable<SqliteItem> GetItems() { lock (wObject) { return wSQLiteConnection.Table<SqliteItem>(); } } // データの登録 public void InsertItem(SqliteItem item) { lock (wObject) { wSQLiteConnection.Insert(item); } } // データの削除 public void DeleteItem(SqliteItem item) { lock (wObject) { wSQLiteConnection.Delete(item); } } }

}

・SqliteInterface.cs

using SQLite.Net;

namespace SampleApp
{

public interface ISqliteInterface { SQLiteConnection GetConnection(); }

}

・SqliteItem.cs

using SQLite.Net.Attributes;

namespace SampleApp
{
public class SqliteItem
{
[PrimaryKey, AutoIncrement]
public int ID { get; set; }
public string Text { get; set; }
public DateTime InsertDate { get; set; }
}
}

画面プロジェクト側

・AppSaml.cs

using Xamarin.Forms;

namespace SampleApp
{
public partial class App : Application
{
public App()
{
InitializeComponent();

MainPage = new SampleApp.SamplePage(); }


}

・SamplePage.cs

using System;
using Xamarin.Forms;
using SQLite.Net;
using SamplePCL;

namespace SampleApp
{
class SamplePage : ContentPage
{
readonly SqliteControl wSqliteControl = new SqliteControl();
public SamplePage()
{
// データ表示用リスト
var wListView = new ListView
{
ItemsSource = wSqliteControl.GetItems(),
ItemTemplate = new DataTemplate(typeof(TextCell))
};
wListView.ItemTemplate.SetBinding(TextCell.TextProperty, "Text");
wListView.ItemTemplate.SetBinding(TextCell.DetailColorProperty, new Binding("InsertDate",
stringFormat: "{0:yyy/MM/dd hh:mm}"));
// データタップ時の処理
wListView.ItemTapped += async (s, a) =>
{
var wItem = (SqliteItem)a.Item;
if (await DisplayAlert("削除しますか", wItem.Text, "はい", "いいえ"))
{
// データの削除
wSqliteControl.DeleteItem(wItem);
// データの再取得
wListView.ItemsSource = wSqliteControl.GetItems();
}
};
// ラベル1
var wLabel1 = new Label
{
Text = "サンプルアプリ (データ登録・削除)",
BackgroundColor = Color.Navy,
TextColor = Color.White,
WidthRequest = 600
};
// ラベル2
var wLabel2 = new Label
{
Text = "登録データ一覧",
BackgroundColor = Color.Gray,
TextColor = Color.White,
WidthRequest = 300
};
// データ入力
var wEntry = new Entry
{
HorizontalOptions = LayoutOptions.FillAndExpand
};
// 登録ボタン
var wButtonIns = new Button
{
Text = "登録",
TextColor = Color.White,
WidthRequest = 60
};
// 登録ボタンの押下時の処理
wButtonIns.Clicked += (s, a) =>
{
if (!String.IsNullOrEmpty(wEntry.Text))
{
// 登録データ設定
var item = new SqliteItem
{
Text = wEntry.Text,
InsertDate = DateTime.Now
};
// データの登録
wSqliteControl.InsertItem(item);
// データの再取得
wListView.ItemsSource = wSqliteControl.GetItems();
// 入力データ初期化
wEntry.Text = "";
}
};
// 画面
Content = new StackLayout
{
Padding = new Thickness
(
0,
Device.OnPlatform(20, 0, 0),
0,
0
),
Children =
{
wLabel1,
new StackLayout
{
BackgroundColor = Color.Green,
Padding = 5,
Orientation = StackOrientation.Horizontal,
Children =
{
wEntry, wButtonIns
}
},
wLabel2,
wListView
}
};
}
}
}

画面プロジェクトのAndroid側

MainActivity.cs

namespace SampleApp.Droid
{
[Activity(Label = "SampleApp", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;

base.OnCreate(bundle); global::Xamarin.Forms.Forms.Init(this, bundle); LoadApplication(new App()); } }

}

その後考えたのですが、

http://ticktack.hatenablog.jp/entry/2017/02/06/234012
イメージ説明

非推奨なのでエラーの直接的な原因なのかは定かではないのですが、
この入れ方でもしかしたらうまくいくかもしれないと考えてはいますが、breakの前に数字を置いてもうまくいかずといった状況が今です。
他のアプローチなどアドバイスありましたらよろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

エラーメッセージの通り、
色を指定する箇所に日付を指定しているのが問題ではないでしょうか
System.InvalidOperationException: Cannot convert "2017/08/●● ●●:●●" into Xamarin.Forms.Color

提示されている情報ではエラー箇所まではわかりません
PCL側のコード(画像にあるSamplePage.csが怪しい?)を確認してください

投稿2017/08/25 07:05

編集2017/08/25 07:08
yamataka3

総合スコア145

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

amay077

2017/08/25 07:15

PCL側の SamplePage.xaml かもしれませんね(XAML を使用するコードなら、ですが)。
super1234

2017/08/27 11:00

>yamataka3さん 回答アドバイス頂きありがとうございます。確かにそう読み取れますね。ありがとうございます。8/25としてソリューション全体検索をPCL側と画面側両方で検索したのですが出てこなかったです。念のためコードをすべて載せました。もしよろしければまた助言よろしくお願いいたします。
super1234

2017/08/27 11:02

>amay077さん 回答ありがとうございます。SamplePage.xamlは使用せずcsで画面を構成しています。念のためメインとなるコードを記載追記しました。もしよろしければまたご助言よろしくお願いいたします。
NakamuraYoichi

2017/08/28 00:05

>SamplePage.cs >wListView.ItemTemplate.SetBinding(TextCell.DetailColorProperty, new Binding("InsertDate", >stringFormat: "{0:yyy/MM/dd hh:mm}")); ここでしょうか。正しくは DetailProperty なのでしょう。
super1234

2017/09/01 20:18

お返事遅れてしまいもうしわけありません。回答ありがとうございました。DetailPropertyで試してみます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問