2016-11-29 4 views
-3

저는 Java가 처음이에요. 컴파일에 자주 발생하는 오류가 있습니다. 나는 다른 해결책을 시도했지만 아무 것도 나를 위해 일했다. 그런 다음라는 다른 파일이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(); 
} 
} 

:

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라는 또 다른 파일에서 : 여기 내 Date.java FRM 코드 조각은, 달력을 만들어야합니다 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

.class의 .class를 컴파일하고 있었다. 한 번에 5 개의 파일을 컴파일했을 때 작동했습니다. 고마워 친구! –

+0

하지만 지금부터 모든 파일을 함께 컴파일해야합니까? –

0

classpath/buildpath 문제와 비슷합니다. $ CLASSPATH를 설정하지 않았으므로 -cp 옵션을 사용하지 않았으므로 컴파일 할 때 TaskE 디렉토리에 있어야합니다.

(또는 @chryslis에서 말한 것처럼) 건물을 짓기 위해 Maven이나 Ant와 같은 IDE 또는 빌드 도구를 사용하고 수동으로 javac 명령을 입력 할 때 예기치 않은 기능을 제거하십시오.

+0

/taskE 디렉토리에있을 때 cmd는 파일을 찾을 수 없다고 알려줍니다. –

+0

그런 다음 상대 경로의 파일 경로를 지정하십시오! –

+0

하지만 내가 파일의 디렉토리에있을 때, 또는 경로를 고를 때 무엇이 ​​변경됩니까? –

관련 문제