下面的代碼出現在我嘗試創建的包的主類中。它引用一個名爲Journey的助手類中的對象和方法。在由星號標記的行中調用journeyCost
方法時,我得到一個「非靜態方法不能從靜態上下文中引用」的錯誤。這讓我感到困惑,因爲我的印象是,在第二行創建的Journey對象「thisJourney」構成了類的一個實例,因此意味着上下文不是靜態的。謝謝,Seany。非靜態方法不能從靜態上下文中引用
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);
}
}
請發表(再次...)整個堆棧跟蹤:P – m0skit0 2012-04-10 13:34:56