I am trying to create a class to send information on the day of the week. For some reason when I try to include the class I get an error saying:
CreateCalendarVisuals.java:1: error: cannot access FindDateFindTime
import FindDateFindTime.FindDateFindTime;
^
bad class file: .\FindDateFindTime\FindDateFindTime.class
class file contains wrong class: FindDateFindTime
Please remove or make sure it appears in the correct subdirectory of the classpath.
I have creat this code to find the date/time:
import java.time.LocalDate;
import java.time.DayOfWeek;
import java.time.LocalTime;
public class FindDateFindTime
{
// public static void main(String[] args)
// {
// LocalDate date = LocalDate.now();
// LocalTime time = LocalTime.now();
//
// System.out.println("Date: " + date + "; Time: " + time);
// }
public int dayOfWeek(int year, int month, int day)
{
LocalDate date = LocalDate.of(year, month, day);
DayOfWeek d = date.getDayOfWeek();
return d.getValue();
}
}
the class is public so I don't know why it would say that it cannot access. I am trying to call that class with this code:
import FindDateFindTime.FindDateFindTime;
public class CreateCalendarVisuals
{
public static void main(String[] args)
{
FindDateFindTime d = new FindDateFindTime();
System.out.println(d.dayOfWeek(2021, 04, 24));
}
}
My FindDateFindTime class is in a folder with the same name so I am that is why I have "import FindDateFindTime.FindDateFindTime". I have tried to look this up but I can't seem to find any solutions. I have also tried to do this with a package but it gives me the same issue. Could someone please help, I honestly don't know what to do.
Your class CreateCalendarVisuals
imports the FindDateFindTime
class as FindDateFindTime.FindDateFindTime
; this means that your class FindDateFindTime
belongs to the package FindDateFindTime
so the first line of your class FindDateFindTime
has to be package FindDateFindTime
. Note that according to the package naming conventions your package's name should be rewritten as finddatefindtime
in a finddatefindtime named directory, so your FindDateFindTime
class declaration should be:
package finddatefindtime;
public class FindDateFindTime { ... }
And your CreateCalendarVisuals
class:
import finddatefindtime.FindDateFindTime;
public class CreateCalendarVisuals { ... }