現在、日付(具体的には月と年)を取得して TextView を使用して表示しようとしていますが、プログラムは強制終了しています。
ここで、月と年を「取得」します。
Calendar cCalendar = Calendar.getInstance();
int currentYear = cCalendar.get(Calendar.YEAR);
int currentMonth = cCalendar.get(Calendar.MONTH);
ここで、TextView テキストを設定します。
public void setDateLabel(View v)
{
TextView month = (TextView)findViewById(R.id.monthLabel);
TextView year = (TextView)findViewById(R.id.yearLabel);
year.setText(currentYear);
month.setText(currentMonth);
}
TextView と Button を含む XML を次に示します。
<TextView android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/monthLabel"></TextView>
<TextView android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/yearLabel"></TextView>
<Button android:text="Button" android:onClick="setDateLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/setDate"></Button>
LogCat を取得するためにデバッグで実行しようとしましたが、デバッガーは停止し、ポート 8634 に「接続」されるのを待ちます。