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

你离开我真会死。 提交于 2019-12-02 18:48:13

问题


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???


回答1:


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



来源:https://stackoverflow.com/questions/25472518/audio-not-playing-in-android-android-content-res-resourcesnotfoundexception-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!