Marcel M. Marcel M. - 8 days ago 5
Java Question

Java- "symbol not found"

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

THanks in advance for your help!

Answer

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