obviously my Java Pause was too long…
I have the following classes:
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;
}
}
}
I use the parsing of a String to a Date quite often, that’s why I wanted to have this function only 1 time & static.
I try to access it like this:
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
}
This brings me the error:
The method getDateFromString(String) is undefined for the type timeline
Err… why?
Why can't I call a static method in the constructor of a class?You can call static method in your constructor and no one can stop you unless you don’t have access to the method like access modifier restriction.
There could be problem in your
importstatement .Please checkTimeLineclass is there or is this imported correctly.