あなたのお時間をいただきありがとうございます。ToStringオーバーロードで処理されない例外
私は最近、私が持っていたアイデアを開発するために、Xamarin.Androidを使用して試してみることにしました。
しかし、私は私が今まで持っていた奇妙な問題に遭遇しました。上記のクラスで
public class Note : INote
{
public string Content { get; set; }
public DateTime DateTime { get; set; }
public List<ITag> Tags { get; set; }
public override string ToString()
{
try
{
const int maxLength = 20;
if (Content.Length > maxLength)
{
return Content.Substring(0, maxLength - 1);
}
return Content;
}
catch (Exception)
{
return Content;
}
}
}
私はそれ未満20文字でノートオブジェクトのToStringメソッドの操作を行うとき、私は未処理の例外を取得します。私はかなり奇妙だと思ったので、部分をtry/catchでラップしました。
しかし、私はまだ未処理の例外を取得します。どうすればいいの?
EDIT: 例外ウィンドウもwerid見えます。通常、彼らはこのように見えます。
ToStringは、このコードで行われているListViewの作成時に呼び出されています。ここで
[Activity(Label = "@string/ApplicationName")]
public class ShowNotesActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.ShowNotes);
var persistence = new Persistence();
var listView = FindViewById<ListView>(Resource.Id.listView1);
var adapter = new ArrayAdapter<INote>(this, Android.Resource.Layout.SimpleListItem1, persistence.GetAllNotes());
listView.Adapter = adapter;
}
}
あなたは例外を得たとき、入力は何ですか? –
これは、 'Content'が20文字未満のとき、' if'条件の中に入っていると言っていますか?もしそうであれば、 'if'条件にブレークポイントを置き、その時点での' Content.Length'の正確な値を調べることができます。 – Amit
Content.Lengthが20より低い場合は、例外が発生します。それは何でもかまいません。私が試した最後の修正、私は2つのメモを作成しました。 "asdfghjklqwertyuiopz"という内容の例外はありませんでした。そして内容の: "e"例外を引き起こした –