Pregunta

I'm trying to show images upon clicking a button.

These images must come from an array so that i can easily add or delete images without having to edit all of my code.

However the compiler aborts my build and i have 2 errors.

public void showQuestion()
    {
        currentQuestion++;
        imageNumber++;
        if(currentQuestion == questions.length)
            currentQuestion = 0;
        if(imageNumber == myImageList.length)
            imageNumber = 0;
        questionView.setText(questions[currentQuestion]);
        answerView.setText("");
        answerText.setText("");
        imagesview.setImageResource(myImageList[imageNumber]);
    }

the first error is at imageNumber == myImageList.length, saying Multiple markers at this line

  • length cannot be resolved or is not a field
  • myImageList cannot be resolved to a variable

the second error is on images view.setimageResource(myImageList[imageNumber]);

Multiple markers at this line

  • The type of the expression must be an array type but it resolved to ArrayList<Integer>
  • myImageList cannot be resolved to a variable

Edit: The mistake i made was i overlooked that i was using an INT with the .length attribute. and a set instead of a .get!

Hope it helps

¿Fue útil?

Solución

An ArrayList is of type list. Therefore .length should be .size() and myImageList[imageNumber] should be myImageList.get(imageNumber).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top