简体   繁体   中英

Random Image generator app does not want to work on android studio 3.1.4

So for a small assignment, I was tasked with making a program that will generate a random image from a file on the computer

what I did was move the icons from the desktop to the drawable folder

in the image you can see that the files are there under the drawable folder

Here is the user interface

the code is also available in the picture. The issue is that the program would crash after I press the button and no picture is ever shown. It looks perfect to me and at this point, I do not know what is wrong with it

Thank you for whoever answers this

Ps. I am using a mac for this (not sure how important this piece of info is )

Simply replace image.setImageResource(i) by image.setImageResource(array[i]) .

What you want is to access the resource id which is stored in the array.

image.setImageResource(i) you are passing random number in the setImageResources

You are passing wrong Image Resource Id

so replace with the image.setImageResource(array[i]) because your image resources ids stored in this array

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM