I have a flashcard application that should dislplay a random question from a database that feeded by the user (so we don't have the total number of items which are the questions). I used a parameter z which the count of number of items at the runtime and I used the Random() method, but every time it gave me an IllegalArgumentException. here's my code how to count the parameter z:
while (resId1 != 0) {
resId1 = getApplicationContext().getResources().getIdentifier(
fquest + num1, "string", getPackageName());
z = z + 1;
num1 = num1 + 1;
}
this code is working fine but the below code containing an exception I would like your assistance if you don't mind, here the bad code:
Random r1 = new Random(z);
num1 = r1.nextInt(z);
num1 = num1 + 1;
resId1 = getApplicationContext().getResources().getIdentifier(
fquest + num1, "string", getPackageName());
quest1 = getResources().getString(resId1);
q.setText(quest1);
the IllegalArgumentException is exactly at this line:
num1 = r1.nextInt(z);
please any help.
Aucun commentaire:
Enregistrer un commentaire