I need to remove an element of the array based on a match. Here is my method to remove the event.
public boolean removeEvent(int year, int month, int day, int start, int end, String activity)
{
Event newEvent = new Event(year, month, day, start, end, activity);
for (int i = 0; i < 5; i++)
{
if (newEvent.equals(events[i]))
{
events[i] = null;
newEvent = null;
numEvents--;
}
}
When I try
calendarTest1.removeEvent(2000, 1, 1, 1, 1, "Cal Test 1");
nothing happens. I have an element in my array with those values but it does not change that element to null.
This is for homework so I don't really want to be told how to do it, just why this does not work. Thank you.
Here is my equals method:
public boolean equals(Object obj){
Event someEvent = (Event) obj;
if(
this.date == someEvent.date
&&
this.start == someEvent.start
&&
this.end == someEvent.end
&&
this.activity.equals(someEvent.activity))
if(obj == null)
return false;
if(obj instanceof Event)
return true;
else
{
return false;
}
}
I have tried a lot of different things but I still get the NullPointerException Error