android - Randomly selected index in integer array causing crash -


This should be a simple fix, but I can not get it ?!

I want to randomly select an integer from an integer array and a bitmap load of it - sometimes it happens, but most of the time this error occurs - I do not know how I Going out of the array?

At first I have used array.length () and then array.length () -1, but now I am securely using a range between start and end ~ which What I do not want to do

  public int GetRandomNumber (int min, max max) {return minute + (int) (Math.random () * ((max - minimum) + 1)); } Whatever the public null () {integer [] images; Imagines = new integer [9]; Imagines [0] = R. Drourabable splatter1; Imagines [1] = Ardhableable splatter2; Imagines [2] = Ardhableable splatter3; Imagines [3] = R. Drourabable splatter4; Imagines [4] = R. Drourable splatter5; Imagius [5] = Ardrauble. Splatter6; Image id [6] = armorable. Splatter7; Imagines [7] = Arradrouble. Splatter8; Imagines [8] = R. Drableable splatter9; Image id [9] = armorable splatter10; Bitmap asset; {Int RandomIndex = GetRandomNumber (0, 9) for (int i = 0; i & lt; splatters.length; i ++); Asset = BitMapficht. Decode Resources (mContext.getResources (), Imagides [Random Indexes]);    

I get an ArrayIndexOutOfBounds exception

Why this accident?

because

imageIs = new integer [10];

You set up 10 images, but create one of them array size 9. Also see the row in the log, which causes an error. It really helps.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -