samedi 9 avril 2016

How to set random max that the user choose

I'm trying to write simple code that allows the user to chose max number for random commend in one activity and use it in another activity. (The min is 1) I succeeded to call the int variable from activity A to activity B but when I try to use it in the random commend the app crashes.

Here I call for the int:

Intent intent = getIntent();
highNum = intent.getIntExtra("highNum", 0);

And put in the random:

Random random = new Random();
mainNum = random.nextInt(highNum) + 1;

I already checked that the int really equals to a number higher than the defualt - 0.

Aucun commentaire:

Enregistrer un commentaire