public void generateMap(ArrayList<NonPlayableFighter> weakFoes, ArrayList<NonPlayableFighter>
strongFoes){
Map[0][0]=new FoeCell(strongFoes[(int)(Math.random()*8)]);
for(int i=0;i<15;i++){
Map[(int)(Math.random()*9)][(int)(Math.random()*9)]=new FoeCell(weakFoes[(int)(Math.random()*7)]);
}
Random rand;
int randomNum = rand.nextInt((5 - 3) + 1) + 3;
for(int i=0;i<randomNum;i++){
Map[(int)(Math.random()*9)][(int)(Math.random()*9)].equals(Collectible.SENZU_BEAN);
}
Map[(int)(Math.random()*9)][(int)(Math.random()*9)].equals(Collectible.DRAGON_BALL);
}
回答
線
Map[0][0]=new FoeCell(strongFoes[(int)(Math.random()*8)]);
不能編譯,因爲你使用數組訪問符號(用方括號:strongFoes[somenumber]
)上ArrayList
。 ArrayList
不是一個數組,它是一個List
。您不能使用[
和]
,您必須調用其上的方法,如get(someNumber)
和set(someNumber, someObject)
。
這特定的代碼行的內容應是這樣的:
Map[0][0]=new FoeCell(strongFoes.get((int)(Math.random()*8)));
你可以得到一個ArrayIndexOutOfBoundsException
如果沒有在List
足夠的元素。有關如何使用ArrayList
的更多信息,請參見http://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html。
我真的很想知道新的FoeCell()可以返回除FoeCell以外的其他任何東西。我不知道'Map'是什麼或者它是什麼,但它不僅僅是ArrayList的問題 –
@ Marc-Andre我猜Map'定義爲'public static FoeCell [] [] Map = ...' –
但是,如此多的問題在這裏 –
- 1. Groovy的編譯錯誤:意外標記
- 2. Java:xmlpull給我編譯錯誤(http://www.xmlpull.org/)
- 3. FirebaseUI給出編譯錯誤
- 4. 艾瑪給編譯錯誤
- 5. ActiveWorkbook.ConnectionsDisabled是給編譯錯誤
- 6. #在Swift中出現錯誤(如何標記編譯時錯誤)
- 7. 錯誤行:76編譯器:'('標記之前的預期標識符
- 8. Ubuntu上的pycrypto給編譯器錯誤
- 9. sequoyah編譯錯誤,但從命令行編譯錯誤
- 10. 交叉編譯的代碼與升壓給編譯錯誤
- 11. 我不明白爲什麼編譯器給我錯誤代碼
- 12. 記錄類型中的DataTable標籤 - 編譯錯誤
- 13. 編譯器錯誤在'*'標記之前的C:expected')'
- 14. 的Eclipse編譯時給了我一個奇怪的錯誤
- 15. jpa criteriabuilder upper給出編譯錯誤
- 16. Tomcat 8給JSP編譯錯誤
- 17. unordered_map.emplace給編譯器時間錯誤?
- 18. Lua與Cocos2D和Box2D給編譯錯誤
- 19. msi.h給出編譯錯誤DLL
- 20. 簽名google.apis.dll給編譯器錯誤
- 21. 爲什麼這不給編譯錯誤
- 22. 編譯時AlchemyAPI給出錯誤
- 23. JavaScript編譯器在.net給人錯誤
- 24. #include「gmock \ gmock.h」給編譯時錯誤
- 25. uwp繼承基頁給編譯錯誤
- 26. 清單地圖給編譯錯誤
- 27. 安裝paramiko> pycrypto給編譯錯誤
- 28. 爲什麼編譯器給出錯誤?
- 29. C宏給出編譯時錯誤
- 30. VBA for vlookup給編譯錯誤
你收到了什麼錯誤? –
是的。是啊...什麼錯誤? – ifly6
和哪一行? –