2011-11-07 85 views
0

我正在使用此代碼來使用隨機生成器來生成隨機位置。隨機Int IllegualArgumentException

,但我不斷收到此錯誤

11-06 21:33:07.364: ERROR/AndroidRuntime(12796): java.lang.IllegalArgumentException 
11-06 21:33:07.364: ERROR/AndroidRuntime(12796):  at java.util.Random.nextInt(Random.java:186) 

這裏是我使用的代碼。

private void addFace() { 
    Random rand = new Random(); 

     float x = (int) roof.getHeight() + mBallTextureRegion.getWidth(); 
     float minY = mBallTextureRegion.getHeight(); 
     float maxY = (int)(roof.getHeight() - mBallTextureRegion.getHeight()); 
     float rangeY = maxY - minY; 
        //The error points here 
     float y = rand.nextInt((int)rangeY) + minY; 

回答

3

這意味着rangeY是負數。檢查您用於分配該值的邏輯。