| Author |
While working from Head first java, I came across this problem... Please help
|
Mike Kris
Greenhorn
Joined: Jun 08, 2009
Posts: 7
|
|
I think i understand what the problem is, but i am not getting an ideas as to how to fix it...
The code looks like this....
and the error is
D:\Java\Game>javac game.java
game.java:18: setLocationCells( java.util.ArrayList< java.lang.String>) in SimpleD
otCom cannot be applied to (int[])
theDotCom.setLocationCells(locations);
^
1 error
I understand that
int [] locations ... defines locations as an array of int.
public void setLocations(ArrayList<String> loc) ...
the args for setLocations is an object of the ArrayList<String> not an int array.
And thats the complaint in the error, but how do i fix this here....
Kindly type the code for me to fix it....
Thank you,
Mike
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Turn the int[] into an ArrayList<String>.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Mike Kris
Greenhorn
Joined: Jun 08, 2009
Posts: 7
|
|
Thank you Rob
So I gotta change it this way right??
Original: int[] locations = {randomNum, randomNum+1, randomNum+2};
Changed: ArrayList<String> locations = {randomNum, randomNum+1, randomNum+2};
But still this gives me the following error
Can you please help me by writing that part of the code for me.
Thanks a million Rob.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
So I gotta change it this way right??
Original: int[] locations = {randomNum, randomNum+1, randomNum+2};
Changed: ArrayList<String> locations = {randomNum, randomNum+1, randomNum+2};
No.... take a look at the JavaDoc for the java.util.ArrayList class for details on how to use the class.
Can you please help me by writing that part of the code for me.
If you don't do it yourself -- by expecting people to write the code for you -- how are you ever going to learn the subject?
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Mike Kris
Greenhorn
Joined: Jun 08, 2009
Posts: 7
|
|
Yes Henry. I understand. I will try to solve it myself.
Thanks for your advice,
Mike
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
You should check out the APIs of java.lang.Integer and/or java.lang.String for methods that can convert an int into a String.
|
 |
 |
|
|
subject: While working from Head first java, I came across this problem... Please help
|
|
|