Q:

Cannot cast double as int

I'm having a problem in my script where it says I can't convert a double to an integer...
Here's the where the error is noted in the bat:
cm.getPlayer().yellowMessage("You have gained " + 
                getJQ.getCurrentMap() + " JQ points!");

The error is off of the method getCurrentMap(), which is here...
public int getCurrentMap() {
    return maps.get((level - 1));
}

Level is an integer that is incremented every time the player advances a level. What I don't understand is how I'm receiving that error. When I print out the List<Integer> maps, I get a list of numbers. I don't see what's wrong.
Here is how I declare it:
private int level = 0;

Image of Error:

Code:
Code - Look at the methods getCurrentMap and the declaration of maps in the file. Ignore everything else.
Source Code: As you can see level is declared as an int, and getCurrentMap() only details with integers. There main lines that deal with this error are lines 29-32, and lines 59-61, where I push an array with a random value.

A:

If level is a double then the result is a double as well. Java won't convert it to an integer because that would lose information. So you have to make it explicit:
return maps.get((int) (level - 1));

If level (or any other int) is retrieved from JavaScript, the code will not even be executed however. You are assigning a double from JavaScript to an int, so it never even reaches your Java code. Accept a double from JavaScript, then convert it to an integer by casting using (int).
You may want to use Math.ceil first - or another rounding method - if you want to round up instead of down.

