下面的代码出现在我试图创建的包的主类中。它从一个名为 Journey 的帮助器类中引用对象和方法。在星号标记的行中调用journeyCost
方法时,出现“无法从静态上下文引用非静态方法”错误。这让我感到困惑,因为我的印象是在第二行中创建的 Journey 对象“thisJourney”构成了该类的一个实例,因此意味着上下文不是静态的。在此先感谢,西尼。
public boolean journey(int date, int time, int busNumber, int journeyType){
Journey thisJourney = new Journey(date, time, busNumber, journeyType);
if (thisJourney.isInSequence(date, time) == false)
{
return false;
}
else
{
Journey.updateCurrentCharges(date);
thisJourney.costOfJourney = Journey.journeyCost(thisJourney);*****
Journey.dayCharge = Journey.dayCharge + thisJourney.costOfJourney;
Journey.weekCharge = Journey.weekCharge + thisJourney.costOfJourney;
Journey.monthCharge = Journey.monthCharge + thisJourney.costOfJourney;
Balance = Balance - thisJourney.costOfJourney;
jArray.add(thisJourney);
}
}