lundi 24 février 2020

I cant display my downloaded images on my app

in the update status method:

public void updateStatus() {

    Random random = new Random();
    URLSize = celebURLs.size();

    if (URLSize <= 0) {
        URLSize++;
        //chosenImage = random.nextInt(URLSize);
    } else {
        chosenImage = random.nextInt(URLSize);
    }

    ImageDownloader imageDownloader = new ImageDownloader();
    Bitmap celebPics;

    try {
        celebPics = imageDownloader.execute(celebURLs.get(chosenImage)).get();
        imageView.setImageBitmap(celebPics);

        locationOfCorrectAnswer = random.nextInt(4);
        int incorrectAnswer;
        for (int i = 0; i < 4; i++) {
            if (i == locationOfCorrectAnswer) {
                answers[i] = chosenNames.get(chosenImage);
            } else {
                incorrectAnswer = random.nextInt(celebURLs.size());
                while (incorrectAnswer == chosenImage) {
                    incorrectAnswer = random.nextInt(celebURLs.size());
                }
                answers[i] = chosenNames.get(incorrectAnswer);
            }

        }
        button1.setText(String.format("%s", answers[0]));
        button2.setText(String.format("%s", answers[1]));
        button3.setText(String.format("%s", answers[2]));
        button4.setText(String.format("%s", answers[3]));

    } catch (Exception e) {
        e.printStackTrace();
    }

}

I changed the code because it brought up an exception"IllegealArgumentException n must be positive" but even after changing the code to always increment the size of random generated values of the array list, it still wont work




Aucun commentaire:

Enregistrer un commentaire