-3

I'm new to java and I have a pretty common compiling error. I tried other solutions, but nothing worked for me. I have to create a calendar, here is a snippet frm my Date.java:

package edu.kit.informatik.calendar;
public final class Date {

private final int year; // Placeholder value
private final int month; // Placeholder value
private final int day; // Placeholder value

public int dayOfYear;

public Date(int year, int month, int dayOfMonth){
    this.year  = year;
    this.month  = month;
    this.day  = dayOfMonth;
}   
public DateTime atTime(Time time){
    DateTime dateTime = new DateTime(this, time);
    return dateTime;
}
public int getYear(){
    return year;
}
public int getMonthValue(){
    return month;
}
public int getDayOfMonth(){
    return day;
}   
public int getMonth(){
    return Month.ofIndex(month);
}

In another file called DateTime.java i have something like this:

package edu.kit.informatik.calendar;

public final class DateTime {

private final Date date; // Placeholder value
private final Time time; // Placeholder value

public DateTime(Date date, Time time){
    this.date = date;
    this.time = time;
}

public Date getDate(){
    return date;
}
public Time getTime(){
    return time;
}

public int getYear(){
    return date.getYear();
}
public int getMonthValue(){
    return date.getMonthValue();
}
public Month getMonth(){
    return date.getMonth();
}
public int getDayOfYear(){
    return date.getDayOfYear();
}
public int getDayOfMonth(){
    return date.getDayOfMonth();
}
public int getHour(){
    return time.getHour();
}
public int getMinute(){
    return time.getMinute();
}
public int getSecond(){
    return time.getSecond();
}

public String toString(){
    return date.toString() + "T" + time.toString();
}
}

Then there is another file called Time.java, but it just looks like the other two.

When I try to compile the DateTime.java

C:\Users\Marcel\Documents\Programmieren\assignment01-     solution\TaskE\edu\kit\informatik\calendar>javac DateTime.java
DateTime.java:12: error: cannot find symbol
private final Date date; // Placeholder value
              ^
symbol:   class Date
location: class DateTime
DateTime.java:13: error: cannot find symbol
    private final Time time; // Placeholder value
                  ^
  symbol:   class Time
location: class DateTime
DateTime.java:15: error: cannot find symbol
      public DateTime(Date date, Time time){
                      ^
  symbol:   class Date
  location: class DateTime
DateTime.java:15: error: cannot find symbol
        public DateTime(Date date, Time time){
                        ^
  symbol:   class Time
  location: class DateTime
DateTime.java:20: error: cannot find symbol
        public Date getDate(){
               ^
  symbol:   class Date
  location: class DateTime
  DateTime.java:23: error: cannot find symbol
        public Time getTime(){
               ^
symbol:   class Time
location: class DateTime
DateTime.java:33: error: cannot find symbol  
    public Month getMonth(){
           ^
symbol:   class Month
location: class DateTime
7 errors
Tom
  • 16,842
  • 17
  • 45
  • 54
derfium
  • 173
  • 1
  • 3
  • 15

2 Answers2

1

It doesn't know anything about your Date class when you are trying to compile DateTime.java. You need to compile them both if one uses the other:

javac DateTime.java Date.java
Jeremy Gurr
  • 1,613
  • 8
  • 11
0

It sounds like a classpath / buildpath problem. Since you haven't set $CLASSPATH and you didn't use a -cp option, you should be in the TaskE directory when compiling.

Or (as @chryslis says) use an IDE or a build tool like Maven or Ant to do your building, and remove the unpredictability of typing javac commands by hand.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216