0

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.

Cistoran
  • 1,587
  • 15
  • 36
  • 54

1 Answers1

1

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

Theblacknight
  • 575
  • 5
  • 12
  • It seems your call to 'findViewById' is returning null. Found [this](http://stackoverflow.com/questions/2361509/android-textview-settext-show-nullpointer-exception), does it help? – Theblacknight Nov 11 '11 at 20:11