private final int NUM_SOUND_FILES = 4;
private Random rnd = new Random(4);
private int mfile[] = new mfile[NUM_SOUND_FILES]; //the second mfile
//reports error everytime
mfile[0] = R.raw.sound1;
mfile[1] = R.raw.sound2;
mfile[2] = R.raw.sound3;
mfile[3] = R.raw.sound4;
int sndToPlay = rnd.nextInt(NUM_SOUND_FILES);
无论我怎么写,我都会遇到语法错误。当我得到正确的语法时,它强制关闭。这是所谓的“正确”语法,但强制关闭:
private final int NUM_SOUND_FILES = 4;
private Random rnd = new Random(4);
private int mfile[] = new int[NUM_SOUND_FILES];{
mfile[0] = R.raw.sound1;
mfile[1] = R.raw.sound2;
mfile[2] = R.raw.sound3;
mfile[3] = R.raw.sound4;}
答案 0 :(得分:3)
我不是一个Android开发人员,但是第3行的数组声明对我来说看起来并不合适,通常是一个int类型的数组,它将被声明如下:
private int[] mfile = new int[NUM_SOUND_FILES];