简体   繁体   English

随机图像生成器应用程序不想在Android Studio 3.1.4上工作

[英]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 在图像中,您可以看到文件位于drawable文件夹下

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. PS。 I am using a mac for this (not sure how important this piece of info is ) 我为此使用Mac(不确定此信息的重要性)

Simply replace image.setImageResource(i) by image.setImageResource(array[i]) . 只需将image.setImageResource(i)替换为image.setImageResource(array[i])

What you want is to access the resource id which is stored in the array. 您要访问的是存储在数组中的资源ID。

image.setImageResource(i) you are passing random number in the setImageResources image.setImageResource(i)您正在setImageResources中传递随机数

You are passing wrong Image Resource Id 您传递了错误的图片资源ID

so replace with the image.setImageResource(array[i]) because your image resources ids stored in this array 因此,请替换为image.setImageResource(array[i])因为您的图像资源ID存储在此数组中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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