Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Random Number

Tags:

java

android

I m generating one random card from array. and assigning it.' Below is the code..but its is showing an error. What is the problem?

public void rand() {
    String rank[]=  {"tclub1.png", "tclub2.png", "tclub3.png", "tclub4.png", "tclub5.png", "tclub6.png", "tclub7.png", "tclub8.png", "tclub9.png", "tclub10.png","tclub11.png", "tclub12.png", "tclub13.png"};

    Random randInt = new Random();

    int b = randInt.nextInt((rank.length));
    showcard1.setBackgroundResource(b); 
}
like image 244
vivek_Android Avatar asked Feb 08 '26 04:02

vivek_Android


1 Answers

b is an int

so you need rank[b] the array at some point in your code

According to your code maybe it should read showcard1.setBackgroundResource(rank[b]);

like image 139
Jason Byrne Avatar answered Feb 09 '26 17:02

Jason Byrne