Question

Currently I am trying to get the date (Month and Year specifically) and display it using a TextView but my program is force closing.

Here is where I "get" the month and year.

Calendar cCalendar = Calendar.getInstance(); 
int currentYear = cCalendar.get(Calendar.YEAR);
int currentMonth = cCalendar.get(Calendar.MONTH);

Here is where I set the TextView text.

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);
}

Here is the XML with the TextView and Button.

<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>

I try to run it in Debug to get a LogCat but the debugger just stops and waits for it to "attach" on port 8634.

Was it helpful?

Solution

When are you calling 'public void setDateLabel(View v) '

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top