I\'ve got two classes right now: RemindersDAO.java and ViewLocalReminders.java.
I\'m trying to get access to a variable that\'s in ViewLocalReminders.java and I\'m tryin
You're assignment of the reminder id is backwards
id = reminderID;
should read
reminderID = id;
in you setReminderID
method
you have
id = remainderID;
it should be
remainderID = id;
public void setReminderID(long id) {
this.reminderID = id;
System.out.println("Reminder ID Value in Setter: " + reminderID);
}
Your setter method seems wrong. You need to use your IDE's auto generation to create these methods.
I see that you accepted the answer. However, I think I know the problem about your getter-setter bug. It's about the order and order matters...it's like you're giving the instruction step-by-step.
Let me explain...
The first one, your setter method, did a mistake. (See marked comment/s)
public void setReminderID(long id) {
id = reminderID; // --> your argument is id. reminderId field value should be changed not the other way around.
System.out.println("Reminder ID Value in Setter: " + reminderID);
}
Here's the correct setter.
public void setReminderID(long id) {
reminderID = id; // --> "id" is your parameter and that's the reminderID's new value.
System.out.println("Reminder ID Value in Setter: " + reminderID);
}
Next, about the getter. The reason why there's a bug in getter is because you have a wrong order. (See marked comment/s)
public long getReminderID() {
return reminderID;
System.out.println("Reminder ID Value in Getter: " + reminderID); // --> putting this line code after "return" results an error and therefore you won't be able to obtain a number or value!
}
Here's the correct getter. Look carefully the difference.
public long getReminderID() {
System.out.println("Reminder ID Value in Getter: " + reminderID); // --> Anycode before "return" value will be fine.
return reminderID; // --> Always put the "return" value at the last line within a getter method.
}
I hope you can use this correction for your future project in case whenever you need to apply the getter-setter method when you're programming. Remember that it's very important because ordering of the code matters and know where you direct the value changes. Questions?
try using this
this.remainderId = id;
instead of
remainderId = id;
in your model or domain.