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
和哪一行? –