简体   繁体   中英

Audio not playing in android. android.content.res.Resources$NotFoundException: Resource ID #0x0

I am trying to play an audio file in Android but it seems to crash and give a the ResourcesNotFoundException . The audio file is saved in the raw folder inside res. The name of the audio file is determined by a randomly generated number which is then concatenated to "audio".

int res = getResources().getIdentifier ( "audio"+arrayIndex, "raw","com.din.askak" );
MediaPlayer mPlayer = MediaPlayer.create ( MainActivity.this, res );

In the logcat it seems to throw the exception on the line creating the mediaPlayer. I don't know what I seem to be doing wrong???

Use of getIdentifier() function is discouraged. It is much more efficient to retrieve resources by identifier rather than by name.

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