2013-03-22 26 views
-3

我不斷收到這個錯誤,但我不知道是什麼造成它,請問有人能幫我理解嗎?Java數組錯誤「數組需要但int找到」

private int [] arrayFeeCode = new int [5]; 

/** 
* Constructor for objects of class Rally 
*/ 
public Rally(int RC, String Venue, int NumDays, int MaxPlaces, int arrayFeeCode) 
{ 
    // initialise instance variables 


    arrayFeeCode[0] = 0.00; 
    arrayFeeCode[1] = 10.00; 
    arrayFeeCode[2] = 15.50; 
    arrayFeeCode[3] = 17.75; 
    arrayFeeCode[4] = 20.00; 



} 
+0

像@Legend說,你的方法簽名是不正確的 – VirtualTroll 2013-03-22 14:42:10

+4

實際上,R從您的構造函數參數列表中刪除'arrayFeeCode'變量。因爲'arrayFeeCode'被聲明爲一個實例變量,所以你不需要它作爲構造函數參數。 – PermGenError 2013-03-22 14:42:55

+0

你真的需要在你的構造函數中,它似乎是一個實例變量? – 2013-03-22 14:43:21

回答

4

參數arrayFreeCode被聲明爲在方法的int,但你把它當作一個int[]

+0

_不是關於代表 - 它是關於發送消息._已經被解決如此'-1'。 – 2013-03-22 14:52:38

+0

沒關係。只是爲了澄清:在不刷新評論的情況下輸入。另外,我會說你的評論更多的是一個答案,然後評論:) – akaIDIOT 2013-03-22 14:54:56

+1

@Legend:你和akalIDIOT的答案之間有1分鐘,讓我們保持禮貌。答案應該是答案,而不是評論。 – 2013-03-22 14:57:14

1

你把雙打int數組?你需要在其中輸入內容。

+0

這應該是一個評論。這不是答案,這是一個問題。 – 2013-03-22 14:47:42

+0

@Legend很好,他在這裏提到了一點。看看OP的代碼,他試圖將double添加到int數組中。你能做到嗎?你不能這使得這更多的回答,而不是評論:) – PermGenError 2013-03-22 15:02:56

+0

即使當我改變爲整數它仍然給我的錯誤 – user2199680 2013-03-23 02:32:08

0

您不能將Double放入Integer數組中。

變化

private int [] arrayFeeCode = new int [5]; 

private double [] arrayFeeCode = new double [5]; 
0

更改參數arrayFeeCode

public Rally(int RC, String Venue, int NumDays, int MaxPlaces, double[] arrayFeeCode){ 
    arrayFeeCode[0] = 0.00; 
    arrayFeeCode[1] = 10.00; 
    arrayFeeCode[2] = 15.50; 
    arrayFeeCode[3] = 17.75; 
    arrayFeeCode[4] = 20.00; 
}