2016-11-29 48 views
-3

我是新来的java,我有一个很常见的编译错误。我尝试了其他解决方案,但没有为我工作。我要创建一个日历,这里是一个片段FRM我Date.java: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); 
} 

在叫我DateTime.java有这样的事情的另一个文件:

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(); 
} 
} 

再有就是所谓的另一个文件Time.java,但它看起来像另外两个。

当我试图编译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 
+0

你大概还没有编译你的Date类。将两者都传递给'javac',或者甚至更好地使用IDE。 – chrylis

+0

正如我所说,如果这些可以解决我的问题,我没有。 –

+0

@MarcelM。更正 - 其中一个会......但你无法弄清楚许多可能的问题/解决方案中哪一个与你相匹配。 –

回答

1

它不知道,当你试图编译DateTime.java您的Date类东西。如果使用另一个,则需要对它们进行编译:

javac DateTime.java Date.java 
+0

我把它作为回报:javac:invalid flag:Date.class –

+0

我正在编译.java的.class instdt。当我一次编译5个文件的时候它就起作用了。谢谢哥们! –

+0

但是我必须从现在开始一起编译所有文件吗? –

0

听起来像是类路径/构建路径问题。由于您尚未设置$ CLASSPATH,并且您没有使用-cp选项,因此编译时应该位于TaskE目录中。

或者(如@chryslis所说)使用IDE或Maven或Ant等构建工具来完成您的建筑,并消除手动键入javac命令的不可预测性。

+0

当我在/ taskE目录中时,cmd告诉我他找不到该文件。 –

+0

然后给出相对于你的位置的文件路径! –

+0

但是,当我在文件的目录中,或者我喜欢路径时,它会发生什么变化? –