由于某种原因,我得到一个错误,它找不到符号:class TimeClient
我从oracle.com上的java trail中复制了这段代码 这是TimeClient.java:
import java.time.*;
public interface TimeClient {
void setTime(int hour, int minute, int second);
void setDate(int day, int month, int year);
void setDateAndTime(int day, int month, int year,
int hour, int minute, int second); LocalDateTime getLocalDateTime();
}
这是SimpleTimeClient.java文件:
package defaultmethods;
import java.time.*;
import java.lang.*;
import java.util.*;
public class SimpleTimeClient implements TimeClient {
private LocalDateTime dateAndTime;
public SimpleTimeClient() {
dateAndTime = LocalDateTime.now();
}
public void setTime(int hour, int minute, int second) {
LocalDate currentDate = LocalDate.from(dateAndTime);
LocalTime timeToSet = LocalTime.of(hour, minute, second);
dateAndTime = LocalDateTime.of(currentDate, timeToSet);
}
public void setDate(int day, int month, int year) {
LocalDate dateToSet = LocalDate.of(day, month, year);
LocalTime currentTime = LocalTime.from(dateAndTime);
dateAndTime = LocalDateTime.of(dateToSet, currentTime);
}
public void setDateAndTime(int day, int month, int year,
int hour, int minute, int second) {
LocalDate dateToSet = LocalDate.of(day, month, year);
LocalTime timeToSet = LocalTime.of(hour, minute, second);
dateAndTime = LocalDateTime.of(dateToSet, timeToSet);
}
public LocalDateTime getLocalDateTime() {
return dateAndTime;
}
public String toString() {
return dateAndTime.toString();
}
public static void main(String... args) {
TimeClient myTimeClient = new SimpleTimeClient();
System.out.println(myTimeClient.toString());
}
}
以下是错误:
javac SimpleTimeClient.java
SimpleTimeClient.java:7: error: cannot find symbol
public class SimpleTimeClient implements TimeClient {
^
symbol: class TimeClient
SimpleTimeClient.java:43: error: cannot find symbol
TimeClient myTimeClient = new SimpleTimeClient();
^
symbol: class TimeClient
location: class SimpleTimeClient
2 errors
我将文件放在同一目录中,为什么找不到TimeClient.java?这是不是很简单,我错过了?
答案 0 :(得分:0)
做Makoto的建议解决了这个问题。该文件不在名为包的目录中(SimpleTimeClient.java)。