I have a method in Java class file "Day" called enoughTimeChecker. Here is the code for the class
package com.example.calendarviewexample;
import android.app.Application;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import java.time.LocalDate;
import java.util.ArrayList;
public class Day extends AppCompatActivity
{
private LocalDate date;
private int totalTime;
public Day(LocalDate date, int totalTime)
{
this.date = date;
this.totalTime = totalTime;
}
public static ArrayList<Day> listOfDayObjects()
{
ArrayList<Day> listOfDayObjects = new ArrayList<>();
return listOfDayObjects;
}
public static void enoughTimeChecker(LocalDate date, int addedTime)
{
for(int i =0; i<listOfDayObjects().size(); i++)
{
if (listOfDayObjects().get(i).getDate() == date)
{
int x = listOfDayObjects().get(i).getTotalTime();
listOfDayObjects().get(i).setTotalTime(x + addedTime);
Log.d("addedTime", "total time of " + String.valueOf(listOfDayObjects().get(i).getDate()) + "is" + String.valueOf(x + addedTime));
}
}
}
public static void setDayClass(LocalDate currentDate)
{
currentDate = LocalDate.now();
for (int i =0; i<366; i++)
{
Day newDay = new Day(currentDate, 0);
listOfDayObjects().add(newDay);
currentDate = currentDate.plusDays(1);
Log.d("DayClazz", "Class created " + String.valueOf(currentDate) );
}
}
public LocalDate getDate()
{
return date;
}
public void setDate(LocalDate date)
{
this.date = date;
}
public int getTotalTime()
{
return totalTime;
}
public void setTotalTime(int totalTime)
{
this.totalTime = totalTime;
}
}
In the file "EventEditActivity", "enoughTimeChecker" is called from method "Save Action". Here is the Save Action function
public void SaveAction(View view)
{
String taskName = eventNameET.getText().toString();
Task newTask = new Task(taskName, CalendarUtils.selectedDate, time, calculatedTime);
/// this is where the attributes of the task are set
Day.enoughTimeChecker(CalendarUtils.selectedDate, calculatedTime);
Task.taskList.add(newTask);
finish();
}
It should output in the logcat when a task is added but it just doesn't - there's no error message when enoughTimeChecker is called.
I have no idea what the error is, I think there might be something wrong with the array perhaps. I made the array in the Day class file here
public static ArrayList<Day> listOfDayObjects()
{
ArrayList<Day> listOfDayObjects = new ArrayList<>();
return listOfDayObjects;
}
and I made the list of objects here
for (int i =0; i<366; i++)
{
Day newDay = new Day(currentDate, 0);
listOfDayObjects().add(newDay);
currentDate = currentDate.plusDays(1);
}
any help would be appreciated