The operator + is undefined for the argument type(s) String, void
The message means that you are using the + operator on two arguments... The first is the string "" and the compiler is happy with that. The second is "void" and the compiler is
not happy with that. The thing is that the add() method is void: it does not return anything, and hence there is nothing for the + operator to treat as its second argument. (Check its
API documentation to see that)
I've done everything I can think of and am completely lost. Does anyone know how to fix this error?
Well, you fix the error by not including that line! The real question is what code do you use instead? And no-one can really answer that without knowing what it was you were trying to do with that line.
Call add() on the Calendar instance
c perhaps. But recognise that it
will not return anything that can be used to set the label text. Rather it will change the calendar in some way. You are free to get() fields from the calendar, and perhaps one of them is what you want to display in the label.
These fields are a bit cryptic and you might have better luck doing whatever it is you are doing with a
DateFormat instance like SimpleDateFormat or using the date formatting capabilities of printf() and the String
format() methods. There are examples of formatting a calendar instance as text in the
Formatter API docs.
-----
Variables like
c and
label1 are not good. Write your code with a stranger in mind: that stranger might be yourself in 6 months. Choose variables which are descriptive of whatever it is they represent.
yearLabel or something is/will be more meaningful than
label1.