显然我的 Java 暂停时间太长了......
我有以下课程:
public class TimeLine {
public static final String TIME_LINE_DATE_FORMAT = "dd.MM.yyyy";
public TimeLine(Context context, LinearLayout layout)
{
this.context = context;
this.layout = layout;
}
// some methods and stuff
public static Date getDateFromString(String dateString)
{
SimpleDateFormat s = new SimpleDateFormat(TIME_LINE_DATE_FORMAT);
try {
return s.parse(dateString);
} catch (ParseException e) {
e.printStackTrace();
return null;
}
}
}
我经常使用将字符串解析为日期,这就是为什么我希望这个函数只有 1 次和静态。
我尝试像这样访问它:
public class TrackedValue {
private double value;
private String unit;
private Date date;
public TrackedValue()
{
}
public TrackedValue(Date date, String unit, double value)
{
this.date = date;
this.unit = unit;
this.value = value;
}
public TrackedValue(String dateString, String unit, double value)
{
this.date = TimeLine.getDateFromString(dateString); //Here's the error
this.unit = unit;
this.value = value;
}
// some getters and setters here
}
这给我带来了错误: 方法 getDateFromString(String) 未定义类型时间线
呃……为什么?