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;}

最佳答案

我不是Android开发人员,但第3行上的数组声明对我来说并不正确,通常它是一个int类型的数组,该数组的声明如下:

private int[] mfile = new int[NUM_SOUND_FILES];

09-11 23:07