Illegal Modifier for Parameter, only final is permitted
4 replies, posted
[cpp]public ArrayList<String> placeDotCom(int comSize) { // THIS BIT HERE IS WHERE THE ERROR IS DISPLAYED
ArrayList<String> alphaCells = new ArrayList<String>();
String [] alphacoords = new String [comSize];
String temp = null;
int [] coords = new int[comSize];
int attempts = 0;
boolean success = false;
int location = 0;
comCount++;
int incr = 1;
if ((comCount % 2) == 1) {
incr = gridLength;
}
while (!success & attempts++ < 200) {
location = (int) (Math.random() * gridSize);
// System.out.print("try: " + location); // A Cheat!
int x = 0;
success = true;
while (success && x < comSize) {
if (grid[location] == 0) {
coords[x++] = location;
location += incr;
if (location >= gridSize) {
success = false;
}
if (x>0 && (location % gridLength == 0)) {
success = false;
}
} else {
// System.out.print(" used " + location); // Cheat Here too!
success = false;
}
}
}
[/cpp]
The bolded section of this piece of this code is throwing up an Illegal Modifier for Parameter error when I change the public to final the code is then fixed but doesn't allow for the parameter to be passed to it. How do I fix this method?
If it helps I'm using the Head First Java book (page 152) I've tried looking over it again but I can't seem to find where I've gone wrong.
Check your braces. You're missing a closing brace at the end of this method, and if you're also missing one in the code that precedes it, the compiler may be parsing the method declaration as if it's a variable declaration within the preceding method.
Thank you, I didn't see the braces.
Wow java is alot like c++
Syntactically, yes, though there are major differences in how objects work, and in the standard library.
Sorry, you need to Log In to post a reply to this thread.